diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..2048f8d --- /dev/null +++ b/ChangeLog @@ -0,0 +1,32 @@ +Version 1.5.1 +------------- + - C Standards compliance improvements + - Build improvements + +Version 1.5.0 +------------- + - Initial tagged release after fork from ProSystem 1.3e with OpenEmu patches + - Convert from C++ to C + - Partial Expansion Module (XM) support + - XRAM + - XPokey (limited to single Pokey) + - Added support for cartridges with sizes greater than 144k + - Additional bank switching modes and cartridge types + - Multiple bank switching fixes + - Reworked cartridge header detection + - Now properly detects bank switching, RAM, etc. + - Detects Expansion Module (XM) + - Detects High score cartridge + - Detects Pokey at $0450 + - Cartridge database + - Added several new cartridge properties + - Pokey at $0450 + - Default difficulty switch settings + - Expansion Module (XM) enabled/disabled + - High score cartridge enabled/disabled + - Database content + - Fixed incorrect controller settings for Sirius, Crossbow, + and Alien Brigade + - Added many homebrew cartridges + - Fixed issue occurring when Kangaroo and Holey were enabled (caused + background to be displayed, resulting in large black squares) diff --git a/Info.plist b/Info.plist index 955cb04..0374f9a 100644 --- a/Info.plist +++ b/Info.plist @@ -17,7 +17,7 @@ CFBundleSignature ???? CFBundleVersion - 1.4.2 + 1.5.1 NSPrincipalClass OEGameCoreController OEGameCoreClass @@ -37,7 +37,7 @@ OEGameCorePlayerCount 2 OEProjectURL - http://home.comcast.net/~gscottstanton/ + https://gitlab.com/jgemu/prosystem OESystemIdentifiers openemu.system.7800 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dcfa4c2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 Library 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 Library General +Public License instead of this License. diff --git a/Lib/Crypt.h b/Lib/Crypt.h deleted file mode 100755 index f14a628..0000000 --- a/Lib/Crypt.h +++ /dev/null @@ -1,132 +0,0 @@ -/* crypt.h -- base code for crypt/uncrypt ZIPfile - - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - This code is a modified version of crypting code in Infozip distribution - - The encryption/decryption parts of this source code (as opposed to the - non-echoing password parts) were originally written in Europe. The - whole source package can be freely distributed, including from the USA. - (Prior to January 2000, re-export from the US was a violation of US law.) - - This encryption code is a direct transcription of the algorithm from - Roger Schlafly, described by Phil Katz in the file appnote.txt. This - file (appnote.txt) is distributed with the PKZIP program (even in the - version without encryption capabilities). - - If you don't need crypting in your application, just define symbols - NOCRYPT and NOUNCRYPT. - - This code support the "Traditional PKWARE Encryption". - - The new AES encryption added on Zip format by Winzip (see the page - http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong - Encryption is not supported. -*/ - -#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) - -/*********************************************************************** - * Return the next byte in the pseudo-random sequence - */ -static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) -{ - unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an - * unpredictable manner on 16-bit systems; not a problem - * with any known compiler so far, though */ - - temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; - return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); -} - -/*********************************************************************** - * Update the encryption keys with the next byte of plain text - */ -static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) -{ - (*(pkeys+0)) = CRC32((*(pkeys+0)), c); - (*(pkeys+1)) += (*(pkeys+0)) & 0xff; - (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; - { - register int keyshift = (int)((*(pkeys+1)) >> 24); - (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); - } - return c; -} - - -/*********************************************************************** - * Initialize the encryption keys and the random header according to - * the given password. - */ -static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) -{ - *(pkeys+0) = 305419896L; - *(pkeys+1) = 591751049L; - *(pkeys+2) = 878082192L; - while (*passwd != '\0') { - update_keys(pkeys,pcrc_32_tab,(int)*passwd); - passwd++; - } -} - -#define zdecode(pkeys,pcrc_32_tab,c) \ - (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) - -#define zencode(pkeys,pcrc_32_tab,c,t) \ - (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) - -#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED - -#define RAND_HEAD_LEN 12 - /* "last resort" source for second part of crypt seed pattern */ -# ifndef ZCR_SEED2 -# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ -# endif - -static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) - const char *passwd; /* password string */ - unsigned char *buf; /* where to write header */ - int bufSize; - unsigned long* pkeys; - const unsigned long* pcrc_32_tab; - unsigned long crcForCrypting; -{ - int n; /* index in random header */ - int t; /* temporary */ - int c; /* random byte */ - unsigned char header[RAND_HEAD_LEN-2]; /* random header */ - static unsigned calls = 0; /* ensure different random header each time */ - - if (bufSize> 7) & 0xff; - header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); - } - /* Encrypt random header (last two bytes is high word of crc) */ - init_keys(passwd, pkeys, pcrc_32_tab); - for (n = 0; n < RAND_HEAD_LEN-2; n++) - { - buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); - } - buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); - buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); - return n; -} - -#endif diff --git a/Lib/HtmlHelp.h b/Lib/HtmlHelp.h deleted file mode 100755 index 49e2ec5..0000000 --- a/Lib/HtmlHelp.h +++ /dev/null @@ -1,426 +0,0 @@ -/**************************************************************************** -* * -* HtmlHelp.h * -* * -* Copyright (c) 1996-1997, Microsoft Corp. All rights reserved. * -* * -****************************************************************************/ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#ifndef __HTMLHELP_H__ -#define __HTMLHELP_H__ - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -// Defines for Win64 -#ifndef _WIN64 -#define DWORD_PTR DWORD -#endif - -// Commands to pass to HtmlHelp() - -#define HH_DISPLAY_TOPIC 0x0000 -#define HH_HELP_FINDER 0x0000 // WinHelp equivalent -#define HH_DISPLAY_TOC 0x0001 -#define HH_DISPLAY_INDEX 0x0002 -#define HH_DISPLAY_SEARCH 0x0003 -#define HH_SET_WIN_TYPE 0x0004 -#define HH_GET_WIN_TYPE 0x0005 -#define HH_GET_WIN_HANDLE 0x0006 -#define HH_ENUM_INFO_TYPE 0x0007 // Get Info type name, call repeatedly to enumerate, -1 at end -#define HH_SET_INFO_TYPE 0x0008 // Add Info type to filter. -#define HH_SYNC 0x0009 -#define HH_RESERVED1 0x000A -#define HH_RESERVED2 0x000B -#define HH_RESERVED3 0x000C -#define HH_KEYWORD_LOOKUP 0x000D -#define HH_DISPLAY_TEXT_POPUP 0x000E // display string resource id or text in a popup window -#define HH_HELP_CONTEXT 0x000F // display mapped numeric value in dwData -#define HH_TP_HELP_CONTEXTMENU 0x0010 // text popup help, same as WinHelp HELP_CONTEXTMENU -#define HH_TP_HELP_WM_HELP 0x0011 // text popup help, same as WinHelp HELP_WM_HELP -#define HH_CLOSE_ALL 0x0012 // close all windows opened directly or indirectly by the caller -#define HH_ALINK_LOOKUP 0x0013 // ALink version of HH_KEYWORD_LOOKUP -#define HH_GET_LAST_ERROR 0x0014 // not currently implemented // See HHERROR.h -#define HH_ENUM_CATEGORY 0x0015 // Get category name, call repeatedly to enumerate, -1 at end -#define HH_ENUM_CATEGORY_IT 0x0016 // Get category info type members, call repeatedly to enumerate, -1 at end -#define HH_RESET_IT_FILTER 0x0017 // Clear the info type filter of all info types. -#define HH_SET_INCLUSIVE_FILTER 0x0018 // set inclusive filtering method for untyped topics to be included in display -#define HH_SET_EXCLUSIVE_FILTER 0x0019 // set exclusive filtering method for untyped topics to be excluded from display -#define HH_INITIALIZE 0x001C // Initializes the help system. -#define HH_UNINITIALIZE 0x001D // Uninitializes the help system. -#define HH_PRETRANSLATEMESSAGE 0x00fd // Pumps messages. (NULL, NULL, MSG*). -#define HH_SET_GLOBAL_PROPERTY 0x00fc // Set a global property. (NULL, NULL, HH_GPROP) - -#define HHWIN_PROP_TAB_AUTOHIDESHOW (1 << 0) // Automatically hide/show tri-pane window -#define HHWIN_PROP_ONTOP (1 << 1) // Top-most window -#define HHWIN_PROP_NOTITLEBAR (1 << 2) // no title bar -#define HHWIN_PROP_NODEF_STYLES (1 << 3) // no default window styles (only HH_WINTYPE.dwStyles) -#define HHWIN_PROP_NODEF_EXSTYLES (1 << 4) // no default extended window styles (only HH_WINTYPE.dwExStyles) -#define HHWIN_PROP_TRI_PANE (1 << 5) // use a tri-pane window -#define HHWIN_PROP_NOTB_TEXT (1 << 6) // no text on toolbar buttons -#define HHWIN_PROP_POST_QUIT (1 << 7) // post WM_QUIT message when window closes -#define HHWIN_PROP_AUTO_SYNC (1 << 8) // automatically ssync contents and index -#define HHWIN_PROP_TRACKING (1 << 9) // send tracking notification messages -#define HHWIN_PROP_TAB_SEARCH (1 << 10) // include search tab in navigation pane -#define HHWIN_PROP_TAB_HISTORY (1 << 11) // include history tab in navigation pane -#define HHWIN_PROP_TAB_FAVORITES (1 << 12) // include favorites tab in navigation pane -#define HHWIN_PROP_CHANGE_TITLE (1 << 13) // Put current HTML title in title bar -#define HHWIN_PROP_NAV_ONLY_WIN (1 << 14) // Only display the navigation window -#define HHWIN_PROP_NO_TOOLBAR (1 << 15) // Don't display a toolbar -#define HHWIN_PROP_MENU (1 << 16) // Menu -#define HHWIN_PROP_TAB_ADVSEARCH (1 << 17) // Advanced FTS UI. -#define HHWIN_PROP_USER_POS (1 << 18) // After initial creation, user controls window size/position -#define HHWIN_PROP_TAB_CUSTOM1 (1 << 19) // Use custom tab #1 -#define HHWIN_PROP_TAB_CUSTOM2 (1 << 20) // Use custom tab #2 -#define HHWIN_PROP_TAB_CUSTOM3 (1 << 21) // Use custom tab #3 -#define HHWIN_PROP_TAB_CUSTOM4 (1 << 22) // Use custom tab #4 -#define HHWIN_PROP_TAB_CUSTOM5 (1 << 23) // Use custom tab #5 -#define HHWIN_PROP_TAB_CUSTOM6 (1 << 24) // Use custom tab #6 -#define HHWIN_PROP_TAB_CUSTOM7 (1 << 25) // Use custom tab #7 -#define HHWIN_PROP_TAB_CUSTOM8 (1 << 26) // Use custom tab #8 -#define HHWIN_PROP_TAB_CUSTOM9 (1 << 27) // Use custom tab #9 -#define HHWIN_TB_MARGIN (1 << 28) // the window type has a margin - -#define HHWIN_PARAM_PROPERTIES (1 << 1) // valid fsWinProperties -#define HHWIN_PARAM_STYLES (1 << 2) // valid dwStyles -#define HHWIN_PARAM_EXSTYLES (1 << 3) // valid dwExStyles -#define HHWIN_PARAM_RECT (1 << 4) // valid rcWindowPos -#define HHWIN_PARAM_NAV_WIDTH (1 << 5) // valid iNavWidth -#define HHWIN_PARAM_SHOWSTATE (1 << 6) // valid nShowState -#define HHWIN_PARAM_INFOTYPES (1 << 7) // valid apInfoTypes -#define HHWIN_PARAM_TB_FLAGS (1 << 8) // valid fsToolBarFlags -#define HHWIN_PARAM_EXPANSION (1 << 9) // valid fNotExpanded -#define HHWIN_PARAM_TABPOS (1 << 10) // valid tabpos -#define HHWIN_PARAM_TABORDER (1 << 11) // valid taborder -#define HHWIN_PARAM_HISTORY_COUNT (1 << 12) // valid cHistory -#define HHWIN_PARAM_CUR_TAB (1 << 13) // valid curNavType - -#define HHWIN_BUTTON_EXPAND (1 << 1) // Expand/contract button -#define HHWIN_BUTTON_BACK (1 << 2) // Back button -#define HHWIN_BUTTON_FORWARD (1 << 3) // Forward button -#define HHWIN_BUTTON_STOP (1 << 4) // Stop button -#define HHWIN_BUTTON_REFRESH (1 << 5) // Refresh button -#define HHWIN_BUTTON_HOME (1 << 6) // Home button -#define HHWIN_BUTTON_BROWSE_FWD (1 << 7) // not implemented -#define HHWIN_BUTTON_BROWSE_BCK (1 << 8) // not implemented -#define HHWIN_BUTTON_NOTES (1 << 9) // not implemented -#define HHWIN_BUTTON_CONTENTS (1 << 10) // not implemented -#define HHWIN_BUTTON_SYNC (1 << 11) // Sync button -#define HHWIN_BUTTON_OPTIONS (1 << 12) // Options button -#define HHWIN_BUTTON_PRINT (1 << 13) // Print button -#define HHWIN_BUTTON_INDEX (1 << 14) // not implemented -#define HHWIN_BUTTON_SEARCH (1 << 15) // not implemented -#define HHWIN_BUTTON_HISTORY (1 << 16) // not implemented -#define HHWIN_BUTTON_FAVORITES (1 << 17) // not implemented -#define HHWIN_BUTTON_JUMP1 (1 << 18) -#define HHWIN_BUTTON_JUMP2 (1 << 19) -#define HHWIN_BUTTON_ZOOM (1 << 20) -#define HHWIN_BUTTON_TOC_NEXT (1 << 21) -#define HHWIN_BUTTON_TOC_PREV (1 << 22) - -#define HHWIN_DEF_BUTTONS \ - (HHWIN_BUTTON_EXPAND | \ - HHWIN_BUTTON_BACK | \ - HHWIN_BUTTON_OPTIONS | \ - HHWIN_BUTTON_PRINT) - -// Button IDs - -#define IDTB_EXPAND 200 -#define IDTB_CONTRACT 201 -#define IDTB_STOP 202 -#define IDTB_REFRESH 203 -#define IDTB_BACK 204 -#define IDTB_HOME 205 -#define IDTB_SYNC 206 -#define IDTB_PRINT 207 -#define IDTB_OPTIONS 208 -#define IDTB_FORWARD 209 -#define IDTB_NOTES 210 // not implemented -#define IDTB_BROWSE_FWD 211 -#define IDTB_BROWSE_BACK 212 -#define IDTB_CONTENTS 213 // not implemented -#define IDTB_INDEX 214 // not implemented -#define IDTB_SEARCH 215 // not implemented -#define IDTB_HISTORY 216 // not implemented -#define IDTB_FAVORITES 217 // not implemented -#define IDTB_JUMP1 218 -#define IDTB_JUMP2 219 -#define IDTB_CUSTOMIZE 221 -#define IDTB_ZOOM 222 -#define IDTB_TOC_NEXT 223 -#define IDTB_TOC_PREV 224 - -// Notification codes - -#define HHN_FIRST (0U-860U) -#define HHN_LAST (0U-879U) - -#define HHN_NAVCOMPLETE (HHN_FIRST-0) -#define HHN_TRACK (HHN_FIRST-1) -#define HHN_WINDOW_CREATE (HHN_FIRST-2) - -typedef struct tagHHN_NOTIFY -{ - NMHDR hdr; - PCSTR pszUrl; // Multi-byte, null-terminated string -} HHN_NOTIFY; - -typedef struct tagHH_POPUP -{ - int cbStruct; // sizeof this structure - HINSTANCE hinst; // instance handle for string resource - UINT idString; // string resource id, or text id if pszFile is specified in HtmlHelp call - LPCTSTR pszText; // used if idString is zero - POINT pt; // top center of popup window - COLORREF clrForeground; // use -1 for default - COLORREF clrBackground; // use -1 for default - RECT rcMargins; // amount of space between edges of window and text, -1 for each member to ignore - LPCTSTR pszFont; // facename, point size, char set, BOLD ITALIC UNDERLINE -} HH_POPUP; - -typedef struct tagHH_AKLINK -{ - int cbStruct; // sizeof this structure - BOOL fReserved; // must be FALSE (really!) - LPCTSTR pszKeywords; // semi-colon separated keywords - LPCTSTR pszUrl; // URL to jump to if no keywords found (may be NULL) - LPCTSTR pszMsgText; // Message text to display in MessageBox if pszUrl is NULL and no keyword match - LPCTSTR pszMsgTitle; // Message text to display in MessageBox if pszUrl is NULL and no keyword match - LPCTSTR pszWindow; // Window to display URL in - BOOL fIndexOnFail; // Displays index if keyword lookup fails. -} HH_AKLINK; - -enum { - HHWIN_NAVTYPE_TOC, - HHWIN_NAVTYPE_INDEX, - HHWIN_NAVTYPE_SEARCH, - HHWIN_NAVTYPE_FAVORITES, - HHWIN_NAVTYPE_HISTORY, // not implemented - HHWIN_NAVTYPE_AUTHOR, - HHWIN_NAVTYPE_CUSTOM_FIRST = 11 -}; - -enum { - IT_INCLUSIVE, - IT_EXCLUSIVE, - IT_HIDDEN, -}; - -typedef struct tagHH_ENUM_IT -{ - int cbStruct; // size of this structure - int iType; // the type of the information type ie. Inclusive, Exclusive, or Hidden - LPCSTR pszCatName; // Set to the name of the Category to enumerate the info types in a category; else NULL - LPCSTR pszITName; // volitile pointer to the name of the infotype. Allocated by call. Caller responsible for freeing - LPCSTR pszITDescription; // volitile pointer to the description of the infotype. -} HH_ENUM_IT, *PHH_ENUM_IT; - -typedef struct tagHH_ENUM_CAT -{ - int cbStruct; // size of this structure - LPCSTR pszCatName; // volitile pointer to the category name - LPCSTR pszCatDescription; // volitile pointer to the category description -} HH_ENUM_CAT, *PHH_ENUM_CAT; - -typedef struct tagHH_SET_INFOTYPE -{ - int cbStruct; // the size of this structure - LPCSTR pszCatName; // the name of the category, if any, the InfoType is a member of. - LPCSTR pszInfoTypeName; // the name of the info type to add to the filter -} HH_SET_INFOTYPE, *PHH_SET_INFOTYPE; - -typedef DWORD HH_INFOTYPE; -typedef HH_INFOTYPE* PHH_INFOTYPE; - -enum { - HHWIN_NAVTAB_TOP, - HHWIN_NAVTAB_LEFT, - HHWIN_NAVTAB_BOTTOM, -}; - -#define HH_MAX_TABS 19 // maximum number of tabs - -enum { - HH_TAB_CONTENTS, - HH_TAB_INDEX, - HH_TAB_SEARCH, - HH_TAB_FAVORITES, - HH_TAB_HISTORY, - HH_TAB_AUTHOR, - - HH_TAB_CUSTOM_FIRST = 11, - HH_TAB_CUSTOM_LAST = HH_MAX_TABS -}; - -#define HH_MAX_TABS_CUSTOM (HH_TAB_CUSTOM_LAST - HH_TAB_CUSTOM_FIRST + 1) - -// HH_DISPLAY_SEARCH Command Related Structures and Constants - -#define HH_FTS_DEFAULT_PROXIMITY (-1) - -typedef struct tagHH_FTS_QUERY -{ - int cbStruct; // Sizeof structure in bytes. - BOOL fUniCodeStrings; // TRUE if all strings are unicode. - LPCTSTR pszSearchQuery; // String containing the search query. - LONG iProximity; // Word proximity. - BOOL fStemmedSearch; // TRUE for StemmedSearch only. - BOOL fTitleOnly; // TRUE for Title search only. - BOOL fExecute; // TRUE to initiate the search. - LPCTSTR pszWindow; // Window to display in -} HH_FTS_QUERY; - -// HH_WINTYPE Structure - -typedef struct tagHH_WINTYPE { - int cbStruct; // IN: size of this structure including all Information Types - BOOL fUniCodeStrings; // IN/OUT: TRUE if all strings are in UNICODE - LPCTSTR pszType; // IN/OUT: Name of a type of window - DWORD fsValidMembers; // IN: Bit flag of valid members (HHWIN_PARAM_) - DWORD fsWinProperties; // IN/OUT: Properties/attributes of the window (HHWIN_) - - LPCTSTR pszCaption; // IN/OUT: Window title - DWORD dwStyles; // IN/OUT: Window styles - DWORD dwExStyles; // IN/OUT: Extended Window styles - RECT rcWindowPos; // IN: Starting position, OUT: current position - int nShowState; // IN: show state (e.g., SW_SHOW) - - HWND hwndHelp; // OUT: window handle - HWND hwndCaller; // OUT: who called this window - - HH_INFOTYPE* paInfoTypes; // IN: Pointer to an array of Information Types - - // The following members are only valid if HHWIN_PROP_TRI_PANE is set - - HWND hwndToolBar; // OUT: toolbar window in tri-pane window - HWND hwndNavigation; // OUT: navigation window in tri-pane window - HWND hwndHTML; // OUT: window displaying HTML in tri-pane window - int iNavWidth; // IN/OUT: width of navigation window - RECT rcHTML; // OUT: HTML window coordinates - - LPCTSTR pszToc; // IN: Location of the table of contents file - LPCTSTR pszIndex; // IN: Location of the index file - LPCTSTR pszFile; // IN: Default location of the html file - LPCTSTR pszHome; // IN/OUT: html file to display when Home button is clicked - DWORD fsToolBarFlags; // IN: flags controling the appearance of the toolbar - BOOL fNotExpanded; // IN: TRUE/FALSE to contract or expand, OUT: current state - int curNavType; // IN/OUT: UI to display in the navigational pane - int tabpos; // IN/OUT: HHWIN_NAVTAB_TOP, HHWIN_NAVTAB_LEFT, or HHWIN_NAVTAB_BOTTOM - int idNotify; // IN: ID to use for WM_NOTIFY messages - BYTE tabOrder[HH_MAX_TABS + 1]; // IN/OUT: tab order: Contents, Index, Search, History, Favorites, Reserved 1-5, Custom tabs - int cHistory; // IN/OUT: number of history items to keep (default is 30) - LPCTSTR pszJump1; // Text for HHWIN_BUTTON_JUMP1 - LPCTSTR pszJump2; // Text for HHWIN_BUTTON_JUMP2 - LPCTSTR pszUrlJump1; // URL for HHWIN_BUTTON_JUMP1 - LPCTSTR pszUrlJump2; // URL for HHWIN_BUTTON_JUMP2 - RECT rcMinSize; // Minimum size for window (ignored in version 1) - int cbInfoTypes; // size of paInfoTypes; - LPCTSTR pszCustomTabs; // multiple zero-terminated strings -} HH_WINTYPE, *PHH_WINTYPE; - -enum { - HHACT_TAB_CONTENTS, - HHACT_TAB_INDEX, - HHACT_TAB_SEARCH, - HHACT_TAB_HISTORY, - HHACT_TAB_FAVORITES, - - HHACT_EXPAND, - HHACT_CONTRACT, - HHACT_BACK, - HHACT_FORWARD, - HHACT_STOP, - HHACT_REFRESH, - HHACT_HOME, - HHACT_SYNC, - HHACT_OPTIONS, - HHACT_PRINT, - HHACT_HIGHLIGHT, - HHACT_CUSTOMIZE, - HHACT_JUMP1, - HHACT_JUMP2, - HHACT_ZOOM, - HHACT_TOC_NEXT, - HHACT_TOC_PREV, - HHACT_NOTES, - - HHACT_LAST_ENUM, -}; - -typedef struct tagHHNTRACK -{ - NMHDR hdr; - PCSTR pszCurUrl; // Multi-byte, null-terminated string - int idAction; // HHACT_ value - HH_WINTYPE* phhWinType; // Current window type structure -} HHNTRACK; - -HWND -WINAPI -HtmlHelpA( - HWND hwndCaller, - LPCSTR pszFile, - UINT uCommand, - DWORD_PTR dwData - ); - -HWND -WINAPI -HtmlHelpW( - HWND hwndCaller, - LPCWSTR pszFile, - UINT uCommand, - DWORD_PTR dwData - ); -#ifdef UNICODE -#define HtmlHelp HtmlHelpW -#else -#define HtmlHelp HtmlHelpA -#endif // !UNICODE - -// Use the following for GetProcAddress to load from hhctrl.ocx - -#define ATOM_HTMLHELP_API_ANSI (LPTSTR)((DWORD)((WORD)(14))) -#define ATOM_HTMLHELP_API_UNICODE (LPTSTR)((DWORD)((WORD)(15))) - -/////////////////////////////////////////////////////////////////////////////// -// -// Global Control Properties. -// -typedef enum tagHH_GPROPID -{ - HH_GPROPID_SINGLETHREAD=1, // VARIANT_BOOL: True for single thread - HH_GPROPID_TOOLBAR_MARGIN=2, // long: Provides a left/right margin around the toolbar. - HH_GPROPID_UI_LANGUAGE=3, // long: LangId of the UI. - HH_GPROPID_CURRENT_SUBSET=4, // BSTR: Current subset. - HH_GPROPID_CONTENT_LANGUAGE=5 // long: LandId for desired content. -} HH_GPROPID; - -/////////////////////////////////////////////////////////////////////////////// -// -// Global Property structure -// -#ifdef __oaidl_h__ - -#pragma pack(push, 8) - -typedef struct tagHH_GLOBAL_PROPERTY -{ - HH_GPROPID id; - VARIANT var; -} HH_GLOBAL_PROPERTY ; - -#pragma pack(pop) -#endif - -#ifdef __cplusplus -} -#endif // __cplusplus - -#endif // __HTMLHELP_H__ diff --git a/Lib/Ioapi.h b/Lib/Ioapi.h deleted file mode 100755 index e73a3b2..0000000 --- a/Lib/Ioapi.h +++ /dev/null @@ -1,75 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - files using zlib + zip or unzip API - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant -*/ - -#ifndef _ZLIBIOAPI_H -#define _ZLIBIOAPI_H - - -#define ZLIB_FILEFUNC_SEEK_CUR (1) -#define ZLIB_FILEFUNC_SEEK_END (2) -#define ZLIB_FILEFUNC_SEEK_SET (0) - -#define ZLIB_FILEFUNC_MODE_READ (1) -#define ZLIB_FILEFUNC_MODE_WRITE (2) -#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) - -#define ZLIB_FILEFUNC_MODE_EXISTING (4) -#define ZLIB_FILEFUNC_MODE_CREATE (8) - - -#ifndef ZCALLBACK - -#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) -#define ZCALLBACK CALLBACK -#else -#define ZCALLBACK -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); -typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); -typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); -typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); - -typedef struct zlib_filefunc_def_s -{ - open_file_func zopen_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell_file_func ztell_file; - seek_file_func zseek_file; - close_file_func zclose_file; - testerror_file_func zerror_file; - voidpf opaque; -} zlib_filefunc_def; - - - -void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); - -#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) -#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) -#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) -#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) -#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) -#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) - - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/Lib/Unzip.h b/Lib/Unzip.h deleted file mode 100755 index 19f83b3..0000000 --- a/Lib/Unzip.h +++ /dev/null @@ -1,342 +0,0 @@ -/* unzip.h -- IO for uncompress .zip files using zlib - Version 1.00, September 10th, 2003 - - Copyright (C) 1998-2003 Gilles Vollant - - This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g - WinZip, InfoZip tools and compatible. - Encryption and multi volume ZipFile (span) are not supported. - Old compressions used by old PKZip 1.x are not supported - - - I WAIT FEEDBACK at mail info@winimage.com - Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - -*/ - -/* for more info about .ZIP format, see - http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip - http://www.info-zip.org/pub/infozip/doc/ - PkWare has also a specification at : - ftp://ftp.pkware.com/probdesc.zip -*/ - -#ifndef _unz_H -#define _unz_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -#include "ioapi.h" -#endif - -#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagunzFile__ { int unused; } unzFile__; -typedef unzFile__ *unzFile; -#else -typedef voidp unzFile; -#endif - - -#define UNZ_OK (0) -#define UNZ_END_OF_LIST_OF_FILE (-100) -#define UNZ_ERRNO (Z_ERRNO) -#define UNZ_EOF (0) -#define UNZ_PARAMERROR (-102) -#define UNZ_BADZIPFILE (-103) -#define UNZ_INTERNALERROR (-104) -#define UNZ_CRCERROR (-105) - -/* tm_unz contain date/time info */ -typedef struct tm_unz_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_unz; - -/* unz_global_info structure contain global data about the ZIPfile - These data comes from the end of central dir */ -typedef struct unz_global_info_s -{ - uLong number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info; - - -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_info_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - uLong compressed_size; /* compressed size 4 bytes */ - uLong uncompressed_size; /* uncompressed size 4 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info; - -extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, - const char* fileName2, - int iCaseSensitivity)); -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) -*/ - - -extern unzFile ZEXPORT unzOpen OF((const char *path)); -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer - "zlib/zlib113.zip". - If the zipfile cannot be opened (file don't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. -*/ - -extern unzFile ZEXPORT unzOpen2 OF((const char *path, - zlib_filefunc_def* pzlib_filefunc_def)); -/* - Open a Zip file, like unzOpen, but provide a set of file low level API - for read/write the zip file (see ioapi.h) -*/ - -extern int ZEXPORT unzClose OF((unzFile file)); -/* - Close a ZipFile opened with unzipOpen. - If there is files inside the .Zip opened with unzOpenCurrentFile (see later), - these files MUST be closed with unzipCloseCurrentFile before call unzipClose. - return UNZ_OK if there is no problem. */ - -extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, - unz_global_info *pglobal_info)); -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ - - -extern int ZEXPORT unzGetGlobalComment OF((unzFile file, - char *szComment, - uLong uSizeBuf)); -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ - - -/***************************************************************************/ -/* Unzip package allow you browse the directory of the zipfile */ - -extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ - -extern int ZEXPORT unzGoToNextFile OF((unzFile file)); -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ - -extern int ZEXPORT unzLocateFile OF((unzFile file, - const char *szFileName, - int iCaseSensitivity)); -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ - - -/* ****************************************** */ -/* Ryan supplied functions */ -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_pos_s -{ - uLong pos_in_zip_directory; /* offset in zip file directory */ - uLong num_of_file; /* # of file */ -} unz_file_pos; - -extern int ZEXPORT unzGetFilePos( - unzFile file, - unz_file_pos* file_pos); - -extern int ZEXPORT unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos); - -/* ****************************************** */ - -extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, - unz_file_info *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); -/* - Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain somes info about - the current file - if szFileName!=NULL, the filemane string will be copied in szFileName - (fileNameBufferSize is the size of the buffer) - if extraField!=NULL, the extra field information will be copied in extraField - (extraFieldBufferSize is the size of the buffer). - This is the Central-header version of the extra field - if szComment!=NULL, the comment string of the file will be copied in szComment - (commentBufferSize is the size of the buffer) -*/ - -/***************************************************************************/ -/* for reading the content of the current zipfile, you can open it, read data - from it, and close it (you can close it before reading all the file) - */ - -extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); -/* - Open for reading data the current file in the zipfile. - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, - const char* password)); -/* - Open for reading data the current file in the zipfile. - password is a crypting password - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, - int* method, - int* level, - int raw)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - -extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, - int* method, - int* level, - int raw, - const char* password)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - - -extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); -/* - Close the file in zip opened with unzOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ - -extern int ZEXPORT unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read bytes from the current file (opened by unzOpenCurrentFile) - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ - -extern z_off_t ZEXPORT unztell OF((unzFile file)); -/* - Give the current position in uncompressed data -*/ - -extern int ZEXPORT unzeof OF((unzFile file)); -/* - return 1 if the end of file was reached, 0 elsewhere -*/ - -extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ - -#ifdef __cplusplus -} -#endif - -#endif /* _unz_H */ diff --git a/Lib/Zconf.h b/Lib/Zconf.h deleted file mode 100755 index 759d757..0000000 --- a/Lib/Zconf.h +++ /dev/null @@ -1,323 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2003 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#ifndef ZCONF_H -#define ZCONF_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - */ -#ifdef Z_PREFIX -# define deflateInit_ z_deflateInit_ -# define deflate z_deflate -# define deflateEnd z_deflateEnd -# define inflateInit_ z_inflateInit_ -# define inflate z_inflate -# define inflateEnd z_inflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateSetDictionary z_deflateSetDictionary -# define deflateCopy z_deflateCopy -# define deflateReset z_deflateReset -# define deflatePrime z_deflatePrime -# define deflateParams z_deflateParams -# define deflateBound z_deflateBound -# define inflateInit2_ z_inflateInit2_ -# define inflateSetDictionary z_inflateSetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateCopy z_inflateCopy -# define inflateReset z_inflateReset -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound -# define uncompress z_uncompress -# define adler32 z_adler32 -# define crc32 z_crc32 -# define get_crc_table z_get_crc_table - -# define Byte z_Byte -# define uInt z_uInt -# define uLong z_uLong -# define Bytef z_Bytef -# define charf z_charf -# define intf z_intf -# define uIntf z_uIntf -# define uLongf z_uLongf -# define voidpf z_voidpf -# define voidp z_voidp -#endif - -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif -#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) -# define OS2 -#endif -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) -# define WIN32 -#endif -#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) -# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) -# ifndef SYS16BIT -# define SYS16BIT -# endif -# endif -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#ifdef SYS16BIT -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#ifdef __STDC_VERSION__ -# ifndef STDC -# define STDC -# endif -# if __STDC_VERSION__ >= 199901L -# ifndef STDC99 -# define STDC99 -# endif -# endif -#endif -#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) -# define STDC -#endif -#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) -# define STDC -#endif -#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) -# define STDC -#endif -#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) -# define STDC -#endif - -#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ -# define STDC -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const /* note: need a more gentle solution here */ -# endif -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) -# define NO_DUMMY_DECL -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#ifdef SYS16BIT -# if defined(M_I86SM) || defined(M_I86MM) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -# endif -# if (defined(__SMALL__) || defined(__MEDIUM__)) - /* Turbo C small or medium model */ -# define SMALL_MEDIUM -# ifdef __BORLANDC__ -# define FAR _far -# else -# define FAR far -# endif -# endif -#endif - -#if defined(WINDOWS) || defined(WIN32) - /* If building or using zlib as a DLL, define ZLIB_DLL. - * This is not mandatory, but it offers a little performance increase. - */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -# endif -# endif /* ZLIB_DLL */ - /* If building or using zlib with the WINAPI/WINAPIV calling convention, - * define ZLIB_WINAPI. - * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. - */ -# ifdef ZLIB_WINAPI -# ifdef FAR -# undef FAR -# endif -# include - /* No need for _export, use ZLIB.DEF instead. */ - /* For complete Windows compatibility, use WINAPI, not __stdcall. */ -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR CDECL -# endif -# endif -#endif - -#if defined (__BEOS__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT __declspec(dllexport) -# define ZEXPORTVA __declspec(dllexport) -# else -# define ZEXPORT __declspec(dllimport) -# define ZEXPORTVA __declspec(dllimport) -# endif -# endif -#endif - -#ifndef ZEXTERN -# define ZEXTERN extern -#endif -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ -# include /* for off_t */ -# include /* for SEEK_* and off_t */ -# ifdef VMS -# include /* for off_t */ -# endif -# define z_off_t off_t -#endif -#ifndef SEEK_SET -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif -#ifndef z_off_t -# define z_off_t long -#endif - -#if defined(__OS400__) -#define NO_vsnprintf -#endif - -#if defined(__MVS__) -# define NO_vsnprintf -# ifdef FAR -# undef FAR -# endif -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) -# pragma map(deflateInit_,"DEIN") -# pragma map(deflateInit2_,"DEIN2") -# pragma map(deflateEnd,"DEEND") -# pragma map(deflateBound,"DEBND") -# pragma map(inflateInit_,"ININ") -# pragma map(inflateInit2_,"ININ2") -# pragma map(inflateEnd,"INEND") -# pragma map(inflateSync,"INSY") -# pragma map(inflateSetDictionary,"INSEDI") -# pragma map(compressBound,"CMBND") -# pragma map(inflate_table,"INTABL") -# pragma map(inflate_fast,"INFA") -# pragma map(inflate_copyright,"INCOPY") -#endif - -#endif /* ZCONF_H */ diff --git a/Lib/Zip.h b/Lib/Zip.h deleted file mode 100755 index cd38b67..0000000 --- a/Lib/Zip.h +++ /dev/null @@ -1,235 +0,0 @@ -/* zip.h -- IO for compress .zip files using zlib - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - This unzip package allow creates .ZIP file, compatible with PKZip 2.04g - WinZip, InfoZip tools and compatible. - Multi volume ZipFile (span) are not supported. - Encryption compatible with pkzip 2.04g only supported - Old compressions used by old PKZip 1.x are not supported - - For uncompress .zip file, look at unzip.h - - - I WAIT FEEDBACK at mail info@winimage.com - Visit also http://www.winimage.com/zLibDll/unzip.html for evolution - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - -*/ - -/* for more info about .ZIP format, see - http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip - http://www.info-zip.org/pub/infozip/doc/ - PkWare has also a specification at : - ftp://ftp.pkware.com/probdesc.zip -*/ - -#ifndef _zip_H -#define _zip_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -#include "ioapi.h" -#endif - -#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagzipFile__ { int unused; } zipFile__; -typedef zipFile__ *zipFile; -#else -typedef voidp zipFile; -#endif - -#define ZIP_OK (0) -#define ZIP_EOF (0) -#define ZIP_ERRNO (Z_ERRNO) -#define ZIP_PARAMERROR (-102) -#define ZIP_BADZIPFILE (-103) -#define ZIP_INTERNALERROR (-104) - -#ifndef DEF_MEM_LEVEL -# if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -# else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -# endif -#endif -/* default memLevel */ - -/* tm_zip contain date/time info */ -typedef struct tm_zip_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_zip; - -typedef struct -{ - tm_zip tmz_date; /* date in understandable format */ - uLong dosDate; /* if dos_date == 0, tmu_date is used */ -/* uLong flag; */ /* general purpose bit flag 2 bytes */ - - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ -} zip_fileinfo; - -typedef const char* zipcharpc; - - -#define APPEND_STATUS_CREATE (0) -#define APPEND_STATUS_CREATEAFTER (1) -#define APPEND_STATUS_ADDINZIP (2) - -extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); -/* - Create a zipfile. - pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on - an Unix computer "zlib/zlib113.zip". - if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip - will be created at the end of the file. - (useful if the file contain a self extractor code) - if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will - add files in existing zip (be sure you don't add file that doesn't exist) - If the zipfile cannot be opened, the return value is NULL. - Else, the return value is a zipFile Handle, usable with other function - of this zip package. -*/ - -/* Note : there is no delete function into a zipfile. - If you want delete file into a zipfile, you must open a zipfile, and create another - Of couse, you can use RAW reading and writing to copy the file you did not want delte -*/ - -extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, - int append, - zipcharpc* globalcomment, - zlib_filefunc_def* pzlib_filefunc_def)); - -extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level)); -/* - Open a file in the ZIP for writing. - filename : the filename in zip (if NULL, '-' without quote will be used - *zipfi contain supplemental information - if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local - contains the extrafield data the the local header - if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global - contains the extrafield data the the local header - if comment != NULL, comment contain the comment string - method contain the compression method (0 for store, Z_DEFLATED for deflate) - level contain the level of compression (can be Z_DEFAULT_COMPRESSION) -*/ - - -extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw)); - -/* - Same than zipOpenNewFileInZip, except if raw=1, we write raw file - */ - -extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int windowBits, - int memLevel, - int strategy, - const char* password, - uLong crcForCtypting)); - -/* - Same than zipOpenNewFileInZip2, except - windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 - password : crypting password (NULL for no crypting) - crcForCtypting : crc of file to compress (needed for crypting) - */ - - -extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, - const void* buf, - unsigned len)); -/* - Write data in the zipfile -*/ - -extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); -/* - Close the current file in the zipfile -*/ - -extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, - uLong uncompressed_size, - uLong crc32)); -/* - Close the current file in the zipfile, for fiel opened with - parameter raw=1 in zipOpenNewFileInZip2 - uncompressed_size and crc32 are value for the uncompressed size -*/ - -extern int ZEXPORT zipClose OF((zipFile file, - const char* global_comment)); -/* - Close the zipfile -*/ - -#ifdef __cplusplus -} -#endif - -#endif /* _zip_H */ diff --git a/Lib/Zlib.h b/Lib/Zlib.h deleted file mode 100755 index d54ac94..0000000 --- a/Lib/Zlib.h +++ /dev/null @@ -1,1200 +0,0 @@ -/* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.1, November 17th, 2003 - - Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt - (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). -*/ - -#ifndef ZLIB_H -#define ZLIB_H - -#include "zconf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ZLIB_VERSION "1.2.1" -#define ZLIB_VERNUM 0x1210 - -/* - The 'zlib' compression library provides in-memory compression and - decompression functions, including integrity checks of the uncompressed - data. This version of the library supports only one compression method - (deflation) but other algorithms will be added later and will have the same - stream interface. - - Compression can be done in a single step if the buffers are large - enough (for example if an input file is mmap'ed), or can be done by - repeated calls of the compression function. In the latter case, the - application must provide more input and/or consume the output - (providing more output space) before each call. - - The compressed data format used by the in-memory functions is the zlib - format, which is a zlib wrapper documented in RFC 1950, wrapped around a - deflate stream, which is itself documented in RFC 1951. - - The library also supports reading and writing files in gzip (.gz) format - with an interface similar to that of stdio using the functions that start - with "gz". The gzip format is different from the zlib format. gzip is a - gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. - - The zlib format was designed to be compact and fast for use in memory - and on communications channels. The gzip format was designed for single- - file compression on file systems, has a larger header than zlib to maintain - directory information, and uses a different, slower check method than zlib. - - This library does not provide any functions to write gzip files in memory. - However such functions could be easily written using zlib's deflate function, - the documentation in the gzip RFC, and the examples in gzio.c. - - The library does not install any signal handler. The decoder checks - the consistency of the compressed data, so the library should never - crash even in case of corrupted input. -*/ - -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); - -struct internal_state; - -typedef struct z_stream_s { - Bytef *next_in; /* next input byte */ - uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total nb of input bytes read so far */ - - Bytef *next_out; /* next output byte should be put there */ - uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total nb of bytes output so far */ - - char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ - - alloc_func zalloc; /* used to allocate the internal state */ - free_func zfree; /* used to free the internal state */ - voidpf opaque; /* private data object passed to zalloc and zfree */ - - int data_type; /* best guess about the data type: ascii or binary */ - uLong adler; /* adler32 value of the uncompressed data */ - uLong reserved; /* reserved for future use */ -} z_stream; - -typedef z_stream FAR *z_streamp; - -/* - The application must update next_in and avail_in when avail_in has - dropped to zero. It must update next_out and avail_out when avail_out - has dropped to zero. The application must initialize zalloc, zfree and - opaque before calling the init function. All other fields are set by the - compression library and must not be updated by the application. - - The opaque value provided by the application will be passed as the first - parameter for calls of zalloc and zfree. This can be useful for custom - memory management. The compression library attaches no meaning to the - opaque value. - - zalloc must return Z_NULL if there is not enough memory for the object. - If zlib is used in a multi-threaded application, zalloc and zfree must be - thread safe. - - On 16-bit systems, the functions zalloc and zfree must be able to allocate - exactly 65536 bytes, but will not be required to allocate more than this - if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, - pointers returned by zalloc for objects of exactly 65536 bytes *must* - have their offset normalized to zero. The default allocation function - provided by this library ensures this (see zutil.c). To reduce memory - requirements and avoid any allocation of 64K objects, at the expense of - compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). - - The fields total_in and total_out can be used for statistics or - progress reports. After compression, total_in holds the total size of - the uncompressed data and may be saved for use in the decompressor - (particularly if the decompressor wants to decompress everything in - a single step). -*/ - - /* constants */ - -#define Z_NO_FLUSH 0 -#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ -#define Z_SYNC_FLUSH 2 -#define Z_FULL_FLUSH 3 -#define Z_FINISH 4 -#define Z_BLOCK 5 -/* Allowed flush values; see deflate() and inflate() below for details */ - -#define Z_OK 0 -#define Z_STREAM_END 1 -#define Z_NEED_DICT 2 -#define Z_ERRNO (-1) -#define Z_STREAM_ERROR (-2) -#define Z_DATA_ERROR (-3) -#define Z_MEM_ERROR (-4) -#define Z_BUF_ERROR (-5) -#define Z_VERSION_ERROR (-6) -/* Return codes for the compression/decompression functions. Negative - * values are errors, positive values are used for special but normal events. - */ - -#define Z_NO_COMPRESSION 0 -#define Z_BEST_SPEED 1 -#define Z_BEST_COMPRESSION 9 -#define Z_DEFAULT_COMPRESSION (-1) -/* compression levels */ - -#define Z_FILTERED 1 -#define Z_HUFFMAN_ONLY 2 -#define Z_RLE 3 -#define Z_DEFAULT_STRATEGY 0 -/* compression strategy; see deflateInit2() below for details */ - -#define Z_BINARY 0 -#define Z_ASCII 1 -#define Z_UNKNOWN 2 -/* Possible values of the data_type field (though see inflate()) */ - -#define Z_DEFLATED 8 -/* The deflate compression method (the only one supported in this version) */ - -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ - -#define zlib_version zlibVersion() -/* for compatibility with versions < 1.0.2 */ - - /* basic functions */ - -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); -/* The application can compare zlibVersion and ZLIB_VERSION for consistency. - If the first character differs, the library code actually used is - not compatible with the zlib.h header file used by the application. - This check is automatically made by deflateInit and inflateInit. - */ - -/* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); - - Initializes the internal stream state for compression. The fields - zalloc, zfree and opaque must be initialized before by the caller. - If zalloc and zfree are set to Z_NULL, deflateInit updates them to - use default allocation functions. - - The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: - 1 gives best speed, 9 gives best compression, 0 gives no compression at - all (the input data is simply copied a block at a time). - Z_DEFAULT_COMPRESSION requests a default compromise between speed and - compression (currently equivalent to level 6). - - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if level is not a valid compression level, - Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible - with the version assumed by the caller (ZLIB_VERSION). - msg is set to null if there is no error message. deflateInit does not - perform any compression: this will be done by deflate(). -*/ - - -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); -/* - deflate compresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce some - output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. deflate performs one or both of the - following actions: - - - Compress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in and avail_in are updated and - processing will resume at this point for the next call of deflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. This action is forced if the parameter flush is non zero. - Forcing flush frequently degrades the compression ratio, so this parameter - should be set only when necessary (in interactive applications). - Some output may be provided even if flush is not set. - - Before the call of deflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating avail_in or avail_out accordingly; avail_out - should never be zero before the call. The application can consume the - compressed output when it wants, for example when the output buffer is full - (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK - and with zero avail_out, it must be called again after making room in the - output buffer because there might be more output pending. - - If the parameter flush is set to Z_SYNC_FLUSH, all pending output is - flushed to the output buffer and the output is aligned on a byte boundary, so - that the decompressor can get all input data available so far. (In particular - avail_in is zero after the call if enough output space has been provided - before the call.) Flushing may degrade compression for some compression - algorithms and so it should be used only when necessary. - - If flush is set to Z_FULL_FLUSH, all output is flushed as with - Z_SYNC_FLUSH, and the compression state is reset so that decompression can - restart from this point if previous compressed data has been damaged or if - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - the compression. - - If deflate returns with avail_out == 0, this function must be called again - with the same value of the flush parameter and more output space (updated - avail_out), until the flush is complete (deflate returns with non-zero - avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. - - If the parameter flush is set to Z_FINISH, pending input is processed, - pending output is flushed and deflate returns with Z_STREAM_END if there - was enough output space; if deflate returns with Z_OK, this function must be - called again with Z_FINISH and more output space (updated avail_out) but no - more input data, until it returns with Z_STREAM_END or an error. After - deflate has returned Z_STREAM_END, the only possible operations on the - stream are deflateReset or deflateEnd. - - Z_FINISH can be used immediately after deflateInit if all the compression - is to be done in a single step. In this case, avail_out must be at least - the value returned by deflateBound (see below). If deflate does not return - Z_STREAM_END, then it must be called again as described above. - - deflate() sets strm->adler to the adler32 checksum of all input read - so far (that is, total_in bytes). - - deflate() may update data_type if it can make a good guess about - the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered - binary. This field is only for information purposes and does not affect - the compression algorithm in any manner. - - deflate() returns Z_OK if some progress has been made (more input - processed or more output produced), Z_STREAM_END if all input has been - consumed and all output has been produced (only when flush is set to - Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible - (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not - fatal, and deflate() can be called again with more input and more output - space to continue compressing. -*/ - - -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. - - deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the - stream state was inconsistent, Z_DATA_ERROR if the stream was freed - prematurely (some input or output was discarded). In the error case, - msg may be set but then points to a static string (which must not be - deallocated). -*/ - - -/* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); - - Initializes the internal stream state for decompression. The fields - next_in, avail_in, zalloc, zfree and opaque must be initialized before by - the caller. If next_in is not Z_NULL and avail_in is large enough (the exact - value depends on the compression method), inflateInit determines the - compression method from the zlib header and allocates all data structures - accordingly; otherwise the allocation will be deferred to the first call of - inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to - use default allocation functions. - - inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller. msg is set to null if there is no error - message. inflateInit does not perform any decompression apart from reading - the zlib header if present: this will be done by inflate(). (So next_in and - avail_in may be modified, but next_out and avail_out are unchanged.) -*/ - - -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); -/* - inflate decompresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce - some output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. inflate performs one or both of the - following actions: - - - Decompress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in is updated and processing - will resume at this point for the next call of inflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. inflate() provides as much output as possible, until there - is no more input data or no more space in the output buffer (see below - about the flush parameter). - - Before the call of inflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating the next_* and avail_* values accordingly. - The application can consume the uncompressed output when it wants, for - example when the output buffer is full (avail_out == 0), or after each - call of inflate(). If inflate returns Z_OK and with zero avail_out, it - must be called again after making room in the output buffer because there - might be more output pending. - - The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, - Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much - output as possible to the output buffer. Z_BLOCK requests that inflate() stop - if and when it get to the next deflate block boundary. When decoding the zlib - or gzip format, this will cause inflate() to return immediately after the - header and before the first block. When doing a raw inflate, inflate() will - go ahead and process the first block, and will return when it gets to the end - of that block, or when it runs out of data. - - The Z_BLOCK option assists in appending to or combining deflate streams. - Also to assist in this, on return inflate() will set strm->data_type to the - number of unused bits in the last byte taken from strm->next_in, plus 64 - if inflate() is currently decoding the last block in the deflate stream, - plus 128 if inflate() returned immediately after decoding an end-of-block - code or decoding the complete header up to just before the first byte of the - deflate stream. The end-of-block will not be indicated until all of the - uncompressed data from that block has been written to strm->next_out. The - number of unused bits may in general be greater than seven, except when - bit 7 of data_type is set, in which case the number of unused bits will be - less than eight. - - inflate() should normally be called until it returns Z_STREAM_END or an - error. However if all decompression is to be performed in a single step - (a single call of inflate), the parameter flush should be set to - Z_FINISH. In this case all pending input is processed and all pending - output is flushed; avail_out must be large enough to hold all the - uncompressed data. (The size of the uncompressed data may have been saved - by the compressor for this purpose.) The next operation on this stream must - be inflateEnd to deallocate the decompression state. The use of Z_FINISH - is never required, but can be used to inform inflate that a faster approach - may be used for the single inflate() call. - - In this implementation, inflate() always flushes as much output as - possible to the output buffer, and always uses the faster approach on the - first call. So the only effect of the flush parameter in this implementation - is on the return value of inflate(), as noted below, or when it returns early - because Z_BLOCK is used. - - If a preset dictionary is needed after this call (see inflateSetDictionary - below), inflate sets strm-adler to the adler32 checksum of the dictionary - chosen by the compressor and returns Z_NEED_DICT; otherwise it sets - strm->adler to the adler32 checksum of all output produced so far (that is, - total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described - below. At the end of the stream, inflate() checks that its computed adler32 - checksum is equal to that saved by the compressor and returns Z_STREAM_END - only if the checksum is correct. - - inflate() will decompress and check either zlib-wrapped or gzip-wrapped - deflate data. The header type is detected automatically. Any information - contained in the gzip header is not retained, so applications that need that - information should instead use raw inflate, see inflateInit2() below, or - inflateBack() and perform their own processing of the gzip header and - trailer. - - inflate() returns Z_OK if some progress has been made (more input processed - or more output produced), Z_STREAM_END if the end of the compressed data has - been reached and all uncompressed output has been produced, Z_NEED_DICT if a - preset dictionary is needed at this point, Z_DATA_ERROR if the input data was - corrupted (input stream not conforming to the zlib format or incorrect check - value), Z_STREAM_ERROR if the stream structure was inconsistent (for example - if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, - Z_BUF_ERROR if no progress is possible or if there was not enough room in the - output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and - inflate() can be called again with more input and more output space to - continue decompressing. If Z_DATA_ERROR is returned, the application may then - call inflateSync() to look for a good compression block if a partial recovery - of the data is desired. -*/ - - -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. - - inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state - was inconsistent. In the error case, msg may be set but then points to a - static string (which must not be deallocated). -*/ - - /* Advanced functions */ - -/* - The following functions are needed only in some special applications. -*/ - -/* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); - - This is another version of deflateInit with more compression options. The - fields next_in, zalloc, zfree and opaque must be initialized before by - the caller. - - The method parameter is the compression method. It must be Z_DEFLATED in - this version of the library. - - The windowBits parameter is the base two logarithm of the window size - (the size of the history buffer). It should be in the range 8..15 for this - version of the library. Larger values of this parameter result in better - compression at the expense of memory usage. The default value is 15 if - deflateInit is used instead. - - windowBits can also be -8..-15 for raw deflate. In this case, -windowBits - determines the window size. deflate() will then generate raw deflate data - with no zlib header or trailer, and will not compute an adler32 check value. - - windowBits can also be greater than 15 for optional gzip encoding. Add - 16 to windowBits to write a simple gzip header and trailer around the - compressed data instead of a zlib wrapper. The gzip header will have no - file name, no extra data, no comment, no modification time (set to zero), - no header crc, and the operating system will be set to 255 (unknown). - - The memLevel parameter specifies how much memory should be allocated - for the internal compression state. memLevel=1 uses minimum memory but - is slow and reduces compression ratio; memLevel=9 uses maximum memory - for optimal speed. The default value is 8. See zconf.h for total memory - usage as a function of windowBits and memLevel. - - The strategy parameter is used to tune the compression algorithm. Use the - value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a - filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no - string match), or Z_RLE to limit match distances to one (run-length - encoding). Filtered data consists mostly of small values with a somewhat - random distribution. In this case, the compression algorithm is tuned to - compress them better. The effect of Z_FILTERED is to force more Huffman - coding and less string matching; it is somewhat intermediate between - Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as - Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy - parameter only affects the compression ratio but not the correctness of the - compressed output even if it is not set appropriately. - - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid - method). msg is set to null if there is no error message. deflateInit2 does - not perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the compression dictionary from the given byte sequence - without producing any compressed output. This function must be called - immediately after deflateInit, deflateInit2 or deflateReset, before any - call of deflate. The compressor and decompressor must use exactly the same - dictionary (see inflateSetDictionary). - - The dictionary should consist of strings (byte sequences) that are likely - to be encountered later in the data to be compressed, with the most commonly - used strings preferably put towards the end of the dictionary. Using a - dictionary is most useful when the data to be compressed is short and can be - predicted with good accuracy; the data can then be compressed better than - with the default empty dictionary. - - Depending on the size of the compression data structures selected by - deflateInit or deflateInit2, a part of the dictionary may in effect be - discarded, for example if the dictionary is larger than the window size in - deflate or deflate2. Thus the strings most likely to be useful should be - put at the end of the dictionary, not at the front. - - Upon return of this function, strm->adler is set to the adler32 value - of the dictionary; the decompressor may later use this value to determine - which dictionary has been used by the compressor. (The adler32 value - applies to the whole dictionary even if only a subset of the dictionary is - actually used by the compressor.) If a raw deflate was requested, then the - adler32 value is not computed and strm->adler is not set. - - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is - inconsistent (for example if deflate has already been called for this stream - or if the compression method is bsort). deflateSetDictionary does not - perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when several compression strategies will be - tried, for example when there are several ways of pre-processing the input - data with a filter. The streams that will be discarded should then be freed - by calling deflateEnd. Note that deflateCopy duplicates the internal - compression state which can be quite large, so this strategy is slow and - can consume lots of memory. - - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); -/* - This function is equivalent to deflateEnd followed by deflateInit, - but does not free and reallocate all the internal compression state. - The stream will keep the same compression level and any other attributes - that may have been set by deflateInit2. - - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). -*/ - -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); -/* - Dynamically update the compression level and compression strategy. The - interpretation of level and strategy is as in deflateInit2. This can be - used to switch between compression and straight copy of the input data, or - to switch to a different kind of input data requiring a different - strategy. If the compression level is changed, the input available so far - is compressed with the old level (and may be flushed); the new level will - take effect only at the next call of deflate(). - - Before the call of deflateParams, the stream state must be set as for - a call of deflate(), since the currently available input may have to - be compressed and flushed. In particular, strm->avail_out must be non-zero. - - deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR - if strm->avail_out was zero. -*/ - -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); -/* - deflateBound() returns an upper bound on the compressed size after - deflation of sourceLen bytes. It must be called after deflateInit() - or deflateInit2(). This would be used to allocate an output buffer - for deflation in a single pass, and so would be called before deflate(). -*/ - -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, - int bits, - int value)); -/* - deflatePrime() inserts bits in the deflate output stream. The intent - is that this function is used to start off the deflate output with the - bits leftover from a previous deflate stream when appending to it. As such, - this function can only be used for raw deflate, and must be used before the - first deflate() call after a deflateInit2() or deflateReset(). bits must be - less than or equal to 16, and that many of the least significant bits of - value will be inserted in the output. - - deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -/* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); - - This is another version of inflateInit with an extra parameter. The - fields next_in, avail_in, zalloc, zfree and opaque must be initialized - before by the caller. - - The windowBits parameter is the base two logarithm of the maximum window - size (the size of the history buffer). It should be in the range 8..15 for - this version of the library. The default value is 15 if inflateInit is used - instead. windowBits must be greater than or equal to the windowBits value - provided to deflateInit2() while compressing, or it must be equal to 15 if - deflateInit2() was not used. If a compressed stream with a larger window - size is given as input, inflate() will return with the error code - Z_DATA_ERROR instead of trying to allocate a larger window. - - windowBits can also be -8..-15 for raw inflate. In this case, -windowBits - determines the window size. inflate() will then process raw deflate data, - not looking for a zlib or gzip header, not generating a check value, and not - looking for any check values for comparison at the end of the stream. This - is for use with other formats that use the deflate compressed data format - such as zip. Those formats provide their own check values. If a custom - format is developed using the raw deflate format for compressed data, it is - recommended that a check value such as an adler32 or a crc32 be applied to - the uncompressed data as is done in the zlib, gzip, and zip formats. For - most applications, the zlib format should be used as is. Note that comments - above on the use in deflateInit2() applies to the magnitude of windowBits. - - windowBits can also be greater than 15 for optional gzip decoding. Add - 32 to windowBits to enable zlib and gzip decoding with automatic header - detection, or add 16 to decode only the gzip format (the zlib format will - return a Z_DATA_ERROR). - - inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative - memLevel). msg is set to null if there is no error message. inflateInit2 - does not perform any decompression apart from reading the zlib header if - present: this will be done by inflate(). (So next_in and avail_in may be - modified, but next_out and avail_out are unchanged.) -*/ - -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate - if this call returned Z_NEED_DICT. The dictionary chosen by the compressor - can be determined from the adler32 value returned by this call of - inflate. The compressor and decompressor must use exactly the same - dictionary (see deflateSetDictionary). - - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - expected one (incorrect adler32 value). inflateSetDictionary does not - perform any decompression: this will be done by subsequent calls of - inflate(). -*/ - -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); -/* - Skips invalid compressed data until a full flush point (see above the - description of deflate with Z_FULL_FLUSH) can be found, or until all - available input is skipped. No output is provided. - - inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR - if no more input was provided, Z_DATA_ERROR if no flush point has been found, - or Z_STREAM_ERROR if the stream structure was inconsistent. In the success - case, the application may save the current current value of total_in which - indicates where valid compressed data was found. In the error case, the - application may repeatedly call inflateSync, providing more input each time, - until success or end of the input data. -*/ - -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when randomly accessing a large stream. The - first pass through the stream can periodically record the inflate state, - allowing restarting inflate at those points when randomly accessing the - stream. - - inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); -/* - This function is equivalent to inflateEnd followed by inflateInit, - but does not free and reallocate all the internal decompression state. - The stream will keep attributes that may have been set by inflateInit2. - - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). -*/ - -/* -ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits, - unsigned char FAR *window)); - - Initialize the internal stream state for decompression using inflateBack() - calls. The fields zalloc, zfree and opaque in strm must be initialized - before the call. If zalloc and zfree are Z_NULL, then the default library- - derived memory allocation routines are used. windowBits is the base two - logarithm of the window size, in the range 8..15. window is a caller - supplied buffer of that size. Except for special applications where it is - assured that deflate was used with small window sizes, windowBits must be 15 - and a 32K byte window must be supplied to be able to decompress general - deflate streams. - - See inflateBack() for the usage of these routines. - - inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of - the paramaters are invalid, Z_MEM_ERROR if the internal state could not - be allocated, or Z_VERSION_ERROR if the version of the library does not - match the version of the header file. -*/ - -typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); - -ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); -/* - inflateBack() does a raw inflate with a single call using a call-back - interface for input and output. This is more efficient than inflate() for - file i/o applications in that it avoids copying between the output and the - sliding window by simply making the window itself the output buffer. This - function trusts the application to not change the output buffer passed by - the output function, at least until inflateBack() returns. - - inflateBackInit() must be called first to allocate the internal state - and to initialize the state with the user-provided window buffer. - inflateBack() may then be used multiple times to inflate a complete, raw - deflate stream with each call. inflateBackEnd() is then called to free - the allocated state. - - A raw deflate stream is one with no zlib or gzip header or trailer. - This routine would normally be used in a utility that reads zip or gzip - files and writes out uncompressed files. The utility would decode the - header and process the trailer on its own, hence this routine expects - only the raw deflate stream to decompress. This is different from the - normal behavior of inflate(), which expects either a zlib or gzip header and - trailer around the deflate stream. - - inflateBack() uses two subroutines supplied by the caller that are then - called by inflateBack() for input and output. inflateBack() calls those - routines until it reads a complete deflate stream and writes out all of the - uncompressed data, or until it encounters an error. The function's - parameters and return types are defined above in the in_func and out_func - typedefs. inflateBack() will call in(in_desc, &buf) which should return the - number of bytes of provided input, and a pointer to that input in buf. If - there is no input available, in() must return zero--buf is ignored in that - case--and inflateBack() will return a buffer error. inflateBack() will call - out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() - should return zero on success, or non-zero on failure. If out() returns - non-zero, inflateBack() will return with an error. Neither in() nor out() - are permitted to change the contents of the window provided to - inflateBackInit(), which is also the buffer that out() uses to write from. - The length written by out() will be at most the window size. Any non-zero - amount of input may be provided by in(). - - For convenience, inflateBack() can be provided input on the first call by - setting strm->next_in and strm->avail_in. If that input is exhausted, then - in() will be called. Therefore strm->next_in must be initialized before - calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called - immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in - must also be initialized, and then if strm->avail_in is not zero, input will - initially be taken from strm->next_in[0 .. strm->avail_in - 1]. - - The in_desc and out_desc parameters of inflateBack() is passed as the - first parameter of in() and out() respectively when they are called. These - descriptors can be optionally used to pass any information that the caller- - supplied in() and out() functions need to do their job. - - On return, inflateBack() will set strm->next_in and strm->avail_in to - pass back any unused input that was provided by the last in() call. The - return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR - if in() or out() returned an error, Z_DATA_ERROR if there was a format - error in the deflate stream (in which case strm->msg is set to indicate the - nature of the error), or Z_STREAM_ERROR if the stream was not properly - initialized. In the case of Z_BUF_ERROR, an input or output error can be - distinguished using strm->next_in which will be Z_NULL only if in() returned - an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to - out() returning non-zero. (in() will always be called before out(), so - strm->next_in is assured to be defined if out() returns non-zero.) Note - that inflateBack() cannot return Z_OK. -*/ - -ZEXTERN int ZEXPORT inflateBackEnd OF((z_stream FAR *strm)); -/* - All memory allocated by inflateBackInit() is freed. - - inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream - state was inconsistent. -*/ - -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); -/* Return flags indicating compile-time options. - - Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: - 1.0: size of uInt - 3.2: size of uLong - 5.4: size of voidpf (pointer) - 7.6: size of z_off_t - - Compiler, assembler, and debug options: - 8: DEBUG - 9: ASMV or ASMINF -- use ASM code - 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention - 11: 0 (reserved) - - One-time table building (smaller code, but not thread-safe if true): - 12: BUILDFIXED -- build static block decoding tables when needed - 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed - 14,15: 0 (reserved) - - Library content (indicates missing functionality): - 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking - deflate code when not needed) - 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect - and decode gzip streams (to avoid linking crc code) - 18-19: 0 (reserved) - - Operation variations (changes in library functionality): - 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate - 21: FASTEST -- deflate algorithm with only one, lowest compression level - 22,23: 0 (reserved) - - The sprintf variant used by gzprintf (zero is best): - 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format - 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! - 26: 0 = returns value, 1 = void -- 1 means inferred string length returned - - Remainder: - 27-31: 0 (reserved) - */ - - - /* utility functions */ - -/* - The following utility functions are implemented on top of the - basic stream-oriented functions. To simplify the interface, some - default options are assumed (compression level and memory usage, - standard memory allocation functions). The source code of these - utility functions can easily be modified if you need special options. -*/ - -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Compresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be at least the value returned - by compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed buffer. - This function can be used to compress a whole file at once if the - input file is mmap'ed. - compress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer. -*/ - -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); -/* - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ - -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); -/* - compressBound() returns an upper bound on the compressed size after - compress() or compress2() on sourceLen bytes. It would be used before - a compress() or compress2() call to allocate the destination buffer. -*/ - -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to decompress a whole file at once if the - input file is mmap'ed. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. -*/ - - -typedef voidp gzFile; - -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); -/* - Opens a gzip (.gz) file for reading or writing. The mode parameter - is as in fopen ("rb" or "wb") but can also include a compression level - ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for - Huffman only compression as in "wb1h", or 'R' for run-length encoding - as in "wb1R". (See the description of deflateInit2 for more information - about the strategy parameter.) - - gzopen can be used to read a file which is not in gzip format; in this - case gzread will directly read from the file without decompression. - - gzopen returns NULL if the file could not be opened or if there was - insufficient memory to allocate the (de)compression state; errno - can be checked to distinguish the two cases (if errno is zero, the - zlib error is Z_MEM_ERROR). */ - -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); -/* - gzdopen() associates a gzFile with the file descriptor fd. File - descriptors are obtained from calls like open, dup, creat, pipe or - fileno (in the file has been previously opened with fopen). - The mode parameter is as in gzopen. - The next call of gzclose on the returned gzFile will also close the - file descriptor fd, just like fclose(fdopen(fd), mode) closes the file - descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). - gzdopen returns NULL if there was insufficient memory to allocate - the (de)compression state. -*/ - -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); -/* - Dynamically update the compression level or strategy. See the description - of deflateInit2 for the meaning of these parameters. - gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not - opened for writing. -*/ - -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); -/* - Reads the given number of uncompressed bytes from the compressed file. - If the input file was not in gzip format, gzread copies the given number - of bytes into the buffer. - gzread returns the number of uncompressed bytes actually read (0 for - end of file, -1 for error). */ - -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, - voidpc buf, unsigned len)); -/* - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of uncompressed bytes actually written - (0 in case of error). -*/ - -ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); -/* - Converts, formats, and writes the args to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written (0 in case of error). The number of - uncompressed bytes written is limited to 4095. The caller should assure that - this limit is not exceeded. If it is exceeded, then gzprintf() will return - return an error (0) with nothing written. In this case, there may also be a - buffer overflow with unpredictable consequences, which is possible only if - zlib was compiled with the insecure functions sprintf() or vsprintf() - because the secure snprintf() or vsnprintf() functions were not available. -*/ - -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); -/* - Writes the given null-terminated string to the compressed file, excluding - the terminating null character. - gzputs returns the number of characters written, or -1 in case of error. -*/ - -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); -/* - Reads bytes from the compressed file until len-1 characters are read, or - a newline character is read and transferred to buf, or an end-of-file - condition is encountered. The string is then terminated with a null - character. - gzgets returns buf, or Z_NULL in case of error. -*/ - -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); -/* - Writes c, converted to an unsigned char, into the compressed file. - gzputc returns the value that was written, or -1 in case of error. -*/ - -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); -/* - Reads one byte from the compressed file. gzgetc returns this byte - or -1 in case of end of file or error. -*/ - -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); -/* - Push one character back onto the stream to be read again later. - Only one character of push-back is allowed. gzungetc() returns the - character pushed, or -1 on failure. gzungetc() will fail if a - character has been pushed but not read yet, or if c is -1. The pushed - character will be discarded if the stream is repositioned with gzseek() - or gzrewind(). -*/ - -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); -/* - Flushes all pending output into the compressed file. The parameter - flush is as in the deflate() function. The return value is the zlib - error number (see function gzerror below). gzflush returns Z_OK if - the flush parameter is Z_FINISH and all output could be flushed. - gzflush should be called only when strictly necessary because it can - degrade compression. -*/ - -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); -/* - Sets the starting position for the next gzread or gzwrite on the - given compressed file. The offset represents a number of bytes in the - uncompressed data stream. The whence parameter is defined as in lseek(2); - the value SEEK_END is not supported. - If the file is opened for reading, this function is emulated but can be - extremely slow. If the file is opened for writing, only forward seeks are - supported; gzseek then compresses a sequence of zeroes up to the new - starting position. - - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error, in - particular if the file is opened for writing and the new starting position - would be before the current position. -*/ - -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); -/* - Rewinds the given file. This function is supported only for reading. - - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) -*/ - -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); -/* - Returns the starting position for the next gzread or gzwrite on the - given compressed file. This position represents a number of bytes in the - uncompressed data stream. - - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) -*/ - -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); -/* - Returns 1 when EOF has previously been detected reading the given - input stream, otherwise zero. -*/ - -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); -/* - Flushes all pending output if necessary, closes the compressed file - and deallocates all the (de)compression state. The return value is the zlib - error number (see function gzerror below). -*/ - -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); -/* - Returns the error message for the last error which occurred on the - given compressed file. errnum is set to zlib error number. If an - error occurred in the file system and not in the compression library, - errnum is set to Z_ERRNO and the application may consult errno - to get the exact error code. -*/ - -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); -/* - Clears the error and end-of-file flags for file. This is analogous to the - clearerr() function in stdio. This is useful for continuing to read a gzip - file that is being written concurrently. -*/ - - /* checksum functions */ - -/* - These functions are not related to compression but are exported - anyway because they might be useful in applications using the - compression library. -*/ - -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); - -/* - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is NULL, this function returns - the required initial value for the checksum. - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. Usage example: - - uLong adler = adler32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); -*/ - -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); -/* - Update a running crc with the bytes buf[0..len-1] and return the updated - crc. If buf is NULL, this function returns the required initial value - for the crc. Pre- and post-conditioning (one's complement) is performed - within this function so it shouldn't be done by the application. - Usage example: - - uLong crc = crc32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - crc = crc32(crc, buffer, length); - } - if (crc != original_crc) error(); -*/ - - - /* various hacks, don't look :) */ - -/* deflateInit and inflateInit are macros to allow checking the zlib version - * and the compiler's view of z_stream: - */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size)); -#define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) -#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) -#define inflateBackInit(strm, windowBits, window) \ - inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, sizeof(z_stream)) - - -#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) - struct internal_state {int dummy;}; /* hack for buggy compilers */ -#endif - -ZEXTERN const char * ZEXPORT zError OF((int err)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); -ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); - -#ifdef __cplusplus -} -#endif - -#endif /* ZLIB_H */ diff --git a/ProSystem.dat b/ProSystem.dat index 9217f05..0a1e499 100644 --- a/ProSystem.dat +++ b/ProSystem.dat @@ -1,18 +1,18 @@ [4332c24e4f3bc72e7fe1b77adf66c2b7] title=3D Asteroids type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=true +pokey450=0 +xm=0 +hsc=1 [0be996d25144966d5541c9eb4919b289] title=Ace Of Aces type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -20,7 +20,7 @@ flags=0 [aadde920b3aaba03bc10b40bd0619c94] title=Ace Of Aces type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -28,7 +28,7 @@ flags=0 [877dcc97a775ed55081864b2dbf5f1e2] title=Alien Brigade type=2 -pokey=false +pokey=0 controller1=2 controller2=2 region=0 @@ -38,7 +38,7 @@ crossy=15 [de3e9496cb7341f865f27e5a72c7f2f5] title=Alien Brigade type=2 -pokey=false +pokey=0 controller1=2 controller2=2 region=1 @@ -48,7 +48,7 @@ crossy=-20 [510ea66b6375a848a21db019b36078dd] title=Apple Snaffle (Aug 3-Rev 1.30) (2010) type=1 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -56,7 +56,7 @@ flags=0 [404f95103b70975a42cb09946dc3adca] title=Apple Snaffle (Jul 17-Rev 24) (2009) type=3 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -64,7 +64,7 @@ flags=0 [5c66261d7be74184a047f77233919e06] title=Arkanoid type=1 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -73,26 +73,26 @@ hblank=8 [212ee2a6e66d8bb7fbf26f343cc8dc19] title=Arkanoid type=1 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=true +pokey450=1 hblank=8 [07342c78619ba6ffcc61c10e907e3b50] title=Asteroids type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [8fc3a695eaea3984912d98ed4a543376] title=Ballblazer type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -101,7 +101,7 @@ hblank=28 [b558814d54904ce0582e2f6a801d03af] title=Ballblazer type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 @@ -110,7 +110,7 @@ hblank=28 [42682415906c21c6af80e4198403ffda] title=Barnyard Blaster type=1 -pokey=false +pokey=0 controller1=2 controller2=1 region=0 @@ -120,7 +120,7 @@ crossy=10 [babe2bc2976688bafb8b23c192658126] title=Barnyard Blaster type=1 -pokey=false +pokey=0 controller1=2 controller2=1 region=1 @@ -130,7 +130,7 @@ crossy=12 [f5f6b69c5eb4b55fc163158d1a6b423e] title=Basketbrawl type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -138,7 +138,7 @@ flags=0 [fba002089fcfa176454ab507e0eb76cb] title=Basketbrawl type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -146,7 +146,7 @@ flags=0 [3e63be18e480fa63fce5e4c823286e53] title=Beef Drop type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 @@ -154,16 +154,16 @@ flags=0 [5a09946e57dbe30408a8f253a28d07db] title=Centipede type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [38c056a48472d9a9e16ebda5ed91dae7] title=Centipede type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -171,7 +171,7 @@ flags=0 [93e4387864b014c155d7c17877990d1e] title=Choplifter type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -179,7 +179,7 @@ flags=0 [59d4edb0230b5acc918b94f6bc94779f] title=Choplifter type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -187,7 +187,7 @@ flags=0 [2e8e28f6ad8b9b9267d518d880c73ebb] title=Commando type=1 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -195,7 +195,7 @@ flags=0 [55da6c6c3974d013f517e725aa60f48e] title=Commando type=1 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 @@ -203,7 +203,7 @@ flags=0 [db691469128d9a4217ec7e315930b646] title=Crack'ed type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -211,7 +211,7 @@ flags=0 [7cbe78fa06f47ba6516a67a4b003c9ee] title=Crack'ed type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -219,7 +219,7 @@ flags=0 [a94e4560b6ad053a1c24e096f1262ebf] title=Crossbow type=2 -pokey=false +pokey=0 controller1=2 controller2=2 region=0 @@ -229,7 +229,7 @@ crossy=10 [63db371d67a98daec547b2abd5e7aa95] title=Crossbow type=2 -pokey=false +pokey=0 controller1=2 controller2=2 region=1 @@ -239,7 +239,7 @@ crossy=5 [179b76ff729d4849b8f66a502398acae] title=Dark Chambers type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -247,7 +247,7 @@ flags=0 [a2b8e2f159642c4b91de82e9a2928494] title=Dark Chambers type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -255,7 +255,7 @@ flags=0 [95ac811c7d27af0032ba090f28c107bd] title=Desert Falcon type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -263,7 +263,7 @@ flags=0 [2d5d99b993a885b063f9f22ce5e6523d] title=Desert Falcon type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -271,16 +271,16 @@ flags=0 [731879ea82fc0ca245e39e036fe293e6] title=Dig Dug type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [408dca9fc40e2b5d805f403fa0509436] title=Dig Dug type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -288,7 +288,7 @@ flags=0 [5e332fbfc1e0fc74223d2e73271ce650] title=Donkey Kong Jr type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -296,7 +296,7 @@ flags=0 [4dc5f88243250461bd61053b13777060] title=Donkey Kong Jr type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -304,7 +304,7 @@ flags=0 [19f1ee292a23636bd57d408b62de79c7] title=Donkey Kong type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -312,7 +312,7 @@ flags=0 [8e96ef14ce9b5d84bcbc996b66d6d4c7] title=Donkey Kong type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -320,7 +320,7 @@ flags=0 [543484c00ba233736bcaba2da20eeea9] title=Double Dragon type=6 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -328,7 +328,7 @@ flags=0 [de2ebafcf0e37aaa9d0e9525a7f4dd62] title=Double Dragon type=6 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -336,7 +336,7 @@ flags=0 [2251a6a0f3aec84cc0aff66fc9fa91e8] title=F-18 Hornet type=5 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -344,7 +344,7 @@ flags=0 [e7709da8e49d3767301947a0a0b9d2e6] title=F-18 Hornet type=5 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -352,7 +352,7 @@ flags=0 [d25d5d19188e9f149977c49eb0367cd1] title=Fatal Run type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -360,7 +360,7 @@ flags=0 [23505651ac2e47f3637152066c3aa62f] title=Fatal Run type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -368,7 +368,7 @@ flags=0 [07dbbfe612a0a28e283c01545e59f25e] title=Fight Night type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -376,7 +376,7 @@ flags=0 [e80f24e953563e6b61556737d67d3836] title=Fight Night type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -384,16 +384,16 @@ flags=0 [cf76b00244105b8e03cdc37677ec1073] title=Food Fight type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [de0d4f5a9bf1c1bddee3ed2f7ec51209] title=Food Fight type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -401,16 +401,16 @@ flags=0 [fb8d803b328b2e442548f7799cfa9a4a] title=Galaga type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [f5dc7dc8e38072d3d65bd90a660148ce] title=Galaga type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -418,7 +418,7 @@ flags=0 [06204dadc975be5e5e37e7cc66f984cf] title=Gato type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -426,7 +426,7 @@ flags=0 [fd9e78e201b6baafddfd3e1fbfe6ba31] title=Hat Trick type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -434,7 +434,7 @@ flags=0 [0baec96787ce17f390e204de1a136e59] title=Hat Trick type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -442,7 +442,7 @@ flags=0 [c3672482ca93f70eafd9134b936c3feb] title=Ikari Warriors type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -450,7 +450,7 @@ flags=0 [8c2c2a1ea6e9a928a44c3151ba5c1ce3] title=Ikari Warriors type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -458,7 +458,7 @@ flags=0 [baebc9246c087e893dfa489632157180] title=Impossible Mission type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -466,7 +466,7 @@ flags=0 [80dead01ea2db5045f6f4443faa6fce8] title=Impossible Mission type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -474,7 +474,7 @@ flags=0 [045fd12050b7f2b842d5970f2414e912] title=Jinks type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -482,7 +482,7 @@ flags=0 [dfb86f4d06f05ad00cf418f0a59a24f7] title=Jinks type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -490,16 +490,16 @@ flags=0 [f18b3b897a25ab3885b43b4bd141b396] title=Joust type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [f2dae0264a4b4a73762b9d7177e989f6] title=Joust type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -507,7 +507,7 @@ flags=0 [c3a5a8692a423d43d9d28dd5b7d109d9] title=Karateka type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -515,7 +515,7 @@ flags=0 [5e0a1e832bbcea6facb832fde23a440a] title=Karateka type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -523,7 +523,7 @@ flags=0 [17b3b764d33eae9b5260f01df7bb9d2f] title=Klax type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -531,7 +531,7 @@ flags=0 [f57d0af323d4e173fb49ed447f0563d7] title=Kung Fu Master type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -539,7 +539,7 @@ flags=0 [2931b75811ad03f3ac9330838f3d231b] title=Kung Fu Master type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -547,7 +547,7 @@ flags=0 [431ca060201ee1f9eb49d44962874049] title=Mario Bros. type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -555,7 +555,7 @@ flags=0 [d2e861306be78e44248bb71d7475d8a3] title=Mario Bros. type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -563,7 +563,7 @@ flags=0 [37b5692e33a98115e574185fa8398c22] title=Mat Mania Challenge type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -571,7 +571,7 @@ flags=0 [6819c37b96063b024898a19dbae2df54] title=Mat Mania Challenge type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -579,7 +579,7 @@ flags=0 [f2f5e5841e4dda89a2faf8933dc33ea6] title=Mean 18 Ultimate Golf type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -587,7 +587,7 @@ flags=0 [2e9dbad6c0fa381a6cd1bb9abf98a104] title=Mean 18 Ultimate Golf type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -595,7 +595,7 @@ flags=0 [bedc30ec43587e0c98fc38c39c1ef9d0] title=Meltdown type=4 -pokey=false +pokey=0 controller1=2 controller2=2 region=0 @@ -605,7 +605,7 @@ crossy=20 [c80155d7eec9e3dcb79aa6b83c9ccd1e] title=Meltdown type=4 -pokey=false +pokey=0 controller1=2 controller2=2 region=1 @@ -615,7 +615,7 @@ crossy=10 [bc1e905db1008493a9632aa83ab4682b] title=Midnight Mutants type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -623,7 +623,7 @@ flags=0 [6794ea31570eba0b88a0bf1ead3f3f1b] title=Midnight Mutants type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -631,7 +631,7 @@ flags=0 [017066f522908081ec3ee624f5e4a8aa] title=Missing in Action type=2 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -639,7 +639,7 @@ flags=3 [3bc8f554cf86f8132a623cc2201a564b] title=Motor Psycho type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -647,7 +647,7 @@ flags=0 [5330bfe428a6b601b7e76c2cfc4cd049] title=Motor Psycho type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -655,16 +655,16 @@ flags=0 [fc0ea52a9fac557251b65ee680d951e5] title=Ms. Pac-Man type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [56469e8c5ff8983c6cb8dadc64eb0363] title=Ms. Pac-Man type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -672,7 +672,7 @@ flags=0 [220121f771fc4b98cef97dc040e8d378] title=Ninja Golf type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -680,7 +680,7 @@ flags=0 [ea0c859aa54fe5eaf4c1f327fab06221] title=Ninja Golf type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -688,7 +688,7 @@ flags=0 [74569571a208f8b0b1ccfb22d7c914e1] title=One On One type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -696,7 +696,7 @@ flags=0 [8dba0425f0262e5704581d8757a1a6e3] title=One On One type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -704,7 +704,7 @@ flags=0 [1a5207870dec6fae9111cb747e20d8e3] title=Pete Rose Baseball type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -712,7 +712,7 @@ flags=0 [386bded4a944bae455fedf56206dd1dd] title=Pete Rose Baseball type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -720,7 +720,7 @@ flags=0 [ec206c8db4316eb1ebce9fc960da7d8f] title=Pit Fighter (Overdump) type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -728,7 +728,7 @@ flags=0 [05f43244465943ce819780a71a5b572a] title=Pit Fighter type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -736,7 +736,7 @@ flags=0 [33aea1e2b6634a1dec8c7006d9afda22] title=Planet Smashers type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -744,7 +744,7 @@ flags=0 [2837a8fd49b7fc7ccd70fd45b69c5099] title=Planet Smashers type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -752,7 +752,7 @@ flags=0 [86546808dc60961cdb1b20e761c50ab1] title=Plutos type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -760,7 +760,7 @@ flags=0 [584582bb09ee8122e7fc09dc7d1ed813] title=Pole Position II type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -768,7 +768,7 @@ flags=0 [865457e0e0f48253b08f77b9e18f93b2] title=Pole Position II type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -776,7 +776,7 @@ flags=0 [1745feadabb24e7cefc375904c73fa4c] title=Possible Mission type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -784,7 +784,7 @@ flags=0 [ac03806cef2558fc795a7d5d8dba7bc0] title=Rampage type=6 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -792,7 +792,7 @@ flags=0 [442761655bb25ddfe5f7ab16bf591c6f] title=Rampart type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -800,7 +800,7 @@ flags=0 [bfad016d6e77eaccec74c0340aded8b9] title=Realsports Baseball (Overdump) type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -808,7 +808,7 @@ flags=0 [383ed9bd1efb9b6cb3388a777678c928] title=Realsports Baseball type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -816,7 +816,7 @@ flags=0 [8f7eb10ad0bd75474abf0c6c36c08486] title=Rescue On Fractalus type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -824,17 +824,17 @@ flags=0 [66ecaafe1b82ae68ffc96267aaf7a4d7] title=Robotron type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -dualanalog=true -hsc=true +dualanalog=1 +hsc=1 [980c35ae9625773a450aa7ef51751c04] title=Scrapyard Dog type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -842,7 +842,7 @@ flags=0 [53db322c201323fe2ca8f074c0a2bf86] title=Scrapyard Dog type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -850,7 +850,7 @@ flags=0 [b697d9c2d1b9f6cb21041286d1bbfa7f] title=Sentinel type=4 -pokey=false +pokey=0 controller1=2 controller2=2 region=0 @@ -860,7 +860,7 @@ crossy=-13 [5469b4de0608f23a5c4f98f331c9e75f] title=Sentinel type=4 -pokey=false +pokey=0 controller1=2 controller2=2 region=1 @@ -870,7 +870,7 @@ crossy=25 [2d643ac548c40e58c99d0fe433ba4ba0] title=Sirius type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -878,7 +878,7 @@ flags=0 [cbb0746192540a13b4c7775c7ce2021f] title=Summer Games type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -886,7 +886,7 @@ flags=0 [cc18e3b37a507c4217eb6cb1de8c8538] title=Super Huey UH-IX type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -894,7 +894,7 @@ flags=0 [162f9c953f0657689cc74ab20b40280f] title=Super Huey UH-IX type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -902,7 +902,7 @@ flags=0 [59b5793bece1c80f77b55d60fb39cb94] title=Super Skatebordin' type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -911,7 +911,7 @@ rightswitch=1 [95d7c321dce8f57623a9c5b4947bb375] title=Super Skatebordin' type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -920,7 +920,7 @@ rightswitch=1 [44f862bca77d68b56b32534eda5c198d] title=Tank Command (Overdump) type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -928,7 +928,7 @@ flags=0 [5c4f752371a523f15e9980fea73b874d] title=Tank Command type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -936,7 +936,7 @@ flags=0 [1af475ff6429a160752b592f0f92b287] title=Title Match Pro Wrestling type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -944,7 +944,7 @@ flags=0 [3bb9c8d9adc912dd7f8471c97445cd8d] title=Title Match Pro Wrestling type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -952,7 +952,7 @@ flags=0 [c3903ab01a51222a52197dbfe6538ecf] title=Tomcat F-14 Simulator type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -960,7 +960,7 @@ flags=0 [682338364243b023ecc9d24f0abfc9a7] title=Tomcat F-14 Simulator type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -968,7 +968,7 @@ flags=0 [208ef955fa90a29815eb097bce89bace] title=Touchdown Football type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -976,7 +976,7 @@ flags=0 [d12e665347f354048b9d13092f7868c9] title=Tower Toppler (Overdump) type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -984,7 +984,7 @@ flags=0 [8d64763db3100aadc552db5e6868506a] title=Tower Toppler type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -992,7 +992,7 @@ flags=0 [32a37244a9c6cc928dcdf02b45365aa8] title=Tower Toppler type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1000,7 +1000,7 @@ flags=0 [acf63758ecf3f3dd03e9d654ae6b69b7] title=Water Ski (Overdump) type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1008,7 +1008,7 @@ flags=0 [427cb05d0a1abb068998e2760d77f4fb] title=Water Ski type=1 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1016,7 +1016,7 @@ flags=0 [3799d72f78dda2ee87b0ef8bf7b91186] title=Winter Games type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1024,7 +1024,7 @@ flags=0 [05fb699db9eef564e2fe45c568746dbc] title=Xenophobe type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1032,7 +1032,7 @@ flags=0 [70937c3184f0be33d06f7f4382ca54de] title=Xenophobe type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1040,16 +1040,16 @@ flags=0 [d7dc17379aa25e5ae3c14b9e780c6f6d] title=Xevious type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [b1a9f196ce5f47ca8caf8fa7bc4ca46c] title=Xevious type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1057,147 +1057,147 @@ flags=0 [e1f0a708fbc107001fc49ce48151fefa] title=Bentley Bear's CQ Wonder Hack type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false +pokey450=0 +xm=0 leftswitch=0 -swapbuttons=true +swapbuttons=1 [34483432b92f565f4ced82a141119164] title=Bentley Bear's Crystal Quest type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=true -xm=false +pokey450=1 +xm=0 leftswitch=0 -swapbuttons=true +swapbuttons=1 [ad35a98040a2facb10ecb120bf83bcc3] title=Bentley Bear's Crystal Quest type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false +pokey450=0 +xm=0 leftswitch=0 -swapbuttons=true +swapbuttons=1 [707e98991390a4e8874508e5ed4edeef] title=Bentley Bear's Crystal Quest type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=true +pokey450=0 +xm=1 leftswitch=0 -swapbuttons=true +swapbuttons=1 [ec81468e31fde04b67b5b99b7da8edb1] title=Bentley Bear's Crystal Quest type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=true +pokey450=0 +xm=1 leftswitch=0 -swapbuttons=true +swapbuttons=1 [87484e54ab8e45aac978dcc3efd924e5] title=Bentley Bear's Crystal Quest P type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=true +pokey450=0 +xm=1 leftswitch=0 -swapbuttons=true +swapbuttons=1 [4d0b5bf95e4cb366990dbaeecb7f706d] title=BentleyBear type=2 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=true +pokey450=0 +xm=1 leftswitch=0 -swapbuttons=true +swapbuttons=1 [ba8d0d0be821b29a0ca9a6fa031a970d] title=BentleyBear type=2 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=true +pokey450=0 +xm=1 leftswitch=0 -swapbuttons=true +swapbuttons=1 [1926b9b322ac0f8f36e119b524aa48bd] title=Bentley Bear's Crystal Quest P type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=true +pokey450=0 +xm=1 leftswitch=0 -swapbuttons=true +swapbuttons=1 [3e4b11a99271fd807b5c6db411dc6643] title=Bentley Bear's Crystal Quest P type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=false +pokey450=0 +xm=0 leftswitch=0 -swapbuttons=true +swapbuttons=1 [8385daccee02ccda081eed45eba1479d] title=Legend Of Silverpeak type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [9ea73fd07e43f61209876d33e6f6dc04] title=Desert Falcon HSC Support type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [90fa275f9f2a65b341796e11b2f551af] title=Winter Games Alternate Version type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1205,18 +1205,18 @@ flags=0 [299d31c8e181fdd011df2014451bdf0f] title=Crazy Brix (Joystick) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 leftswitch=0 rightswitch=1 -hsc=true +hsc=1 [3209039148e0b7a2b1927bd05bae4685] title=Tric Brix (NTSC) (Joy) (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1226,7 +1226,7 @@ rightswitch=1 [32e937e7796db3a01e9bcf5fe93929b0] title=Trix Brix-NoLvl13-NTSC-Joy-Hack type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1236,16 +1236,16 @@ rightswitch=1 [a60e4b608505d1fb201703b266f754a7] title=TiME Salvo type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -dualanalog=true +dualanalog=1 [dbb493bdc4e98436dbbfd4f2e4413397] title=Dig Dog (No Harp) (PAL) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1253,7 +1253,7 @@ flags=0 [54829fb744d4cd7a794ccd2580df7c3d] title=Dig Dog (Harp) (PAL) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1261,7 +1261,7 @@ flags=0 [f2047b149e72be8f97e9671314748ec4] title=ReZolve type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1269,7 +1269,7 @@ flags=0 [42fa4bd854a2813b19099da524461a64] title=Battlezone (PAL) type=7 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1277,17 +1277,17 @@ flags=0 [f5150c0fc1948832211e57852abb0c6e] title=7800 Utility Cart type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -xm=true -hsc=true +xm=1 +hsc=1 [a8458c510fdd71a1f9cc4c0b243b177a] title=Battlezone (NTSC) type=7 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1295,7 +1295,7 @@ flags=0 [67ee0011090a6ada38f3eef8a3020fb4] title=Apple Snaffle V1.25F type=1 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1303,52 +1303,52 @@ flags=0 [13f11c4e8c019ee326b571d059accea4] title=Froggie type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=true +pokey450=1 [608fa599f06f935e05d445ff236f6d7a] title=Asterix Quest (BBCQ Hack) type=2 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -swapbuttons=true +swapbuttons=1 [a65f79ad4a0bbdecd59d5f7eb3623fd7] title=Asteroids Deluxe (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [3d38281ed8a8d8c7cd457a18c92c8604] title=Astro Blaster type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [a51e5df28a0fe8c52e9d28fb5f8e44a6] title=Astro Fighter type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [78b1061d651ef806becac1dd3fda29a0] title=Beef Drop type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1356,7 +1356,7 @@ flags=0 [6010a398070dfacb4c0173d75d73c50a] title=Beef Drop (New Levels Hack) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1364,7 +1364,7 @@ flags=0 [9fa7743a016c9b7015ee1d386326f88e] title=b*nQ type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1372,7 +1372,7 @@ flags=0 [af1c8f89f0aef0d9e2e15901d6e0539a] title=Centipede PMI PAL type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1380,16 +1380,16 @@ flags=0 [2d2fe4da9f1bae102fa8ca2d8830a626] title=Crazy Otto (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [40bd21c9698c6b8e71b703f860c11359] title=Cyb Ur type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1397,36 +1397,36 @@ flags=0 [cf3c5a32205506af3c09e6e0c82cfa09] title=Donkey Kong PK-XM Concerto Demo type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=true -hsc=true +pokey450=1 +hsc=1 [c956d5ce7417cc2dab61a9afd8f372d0] title=Donkey Kong PK-XM Demo NTSC v1.2 type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=true -hsc=true +pokey450=1 +hsc=1 [df700753d8ba9353a7045868778eef6d] title=Donkey Kong PK-XM Demo PAL v1.2 type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 flags=0 -pokey450=true +pokey450=1 [098b209aac126f2c2edbc982df09cd1b] title=Double Dragon GPX Hack type=6 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1434,7 +1434,7 @@ flags=0 [4565867aa6e5cc710a7edaf6d434b3af] title=Double Dragon Sprite Hack Test 2 type=6 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1442,7 +1442,7 @@ flags=0 [fab1290f9a4c4f2b4d831c8a57f969f5] title=Draker Quest (Beta 4) type=1 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1450,7 +1450,7 @@ flags=0 [a9f29004412621f20ad9f5c51cc11486] title=Draker Quest II type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1458,25 +1458,25 @@ flags=0 [fa4aec407b90e9360b9cfeb41839b09a] title=Dual Pac-Man (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [6287727ab36391a62f728bbdee88675c] title=FailSafe (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [84c4b4ed75f41417ac7cbceac71e3856] title=FailSafe (PAL) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1484,7 +1484,7 @@ flags=0 [2fb85cab6e0f0582e3057bf1ac33c74a] title=Fatal Run Graphics Hack RC1 type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1492,26 +1492,26 @@ flags=0 [e7d89669a7f92ec2cc99d9663a28671c] title=Frenzy (w-Berzerk) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -xm=true -hsc=true +xm=1 +hsc=1 [6053233cb59c0b4ca633623fd76c4576] title=Froggie type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [ee09789d61a693e387ccdc9a2f025b43] title=Galaxians (Hack) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1519,7 +1519,7 @@ flags=0 [3d12489c553cb1a90c8ebd6534383fa1] title=Gorf type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1527,7 +1527,7 @@ flags=0 [1e21bf1d9d7b3c0cebaac576964c9eb2] title=Graze Suit Alpha type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1535,16 +1535,16 @@ flags=0 [46dbc5108151e963b120cdaedd7d6d4c] title=Hangly-Man (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [25ce1f5dfc909bcb46086e414d6a0f30] title=Hearty Manslapper type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1552,16 +1552,16 @@ flags=0 [61809684eefd6cbb2963574ffb0a3fab] title=Humantron 2084 type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -dualanalog=true +dualanalog=1 [bf070f04c8fc7ec721b9506b63b48470] title=Impossible Mission (Blue Hack) type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1569,7 +1569,7 @@ flags=0 [4a811d87d1730a334a21e7bda9fe535a] title=Impossible Mission (Green Hack) type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1577,7 +1577,7 @@ flags=0 [05c21a88fd736d59d28b1d95e79840b6] title=Impossible Mission (Red Hack) type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1585,7 +1585,7 @@ flags=0 [dde5703c488c4ad5268c2696704f1c68] title=Impossible Mission (C64 Hack) type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1593,7 +1593,7 @@ flags=0 [f4216cb77cd6db15225968f315c9793f] title=Impossible Mission C64 GPX Hack type=3 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1601,16 +1601,16 @@ flags=0 [e54edc299e72d22d0ba05d16f3393e8c] title=Jr. Pac-Man (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [e274e7285bb8f97d4d9acddc8497ed9e] title=Jr. Pac-Man (PAL) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1618,7 +1618,7 @@ flags=0 [5fb805f2b69820a9b196f5fed2a23c99] title=Klax (Prototype) (Fixed) type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1626,7 +1626,7 @@ flags=0 [114e215b8cfc8698bc0286a79e1cb9b2] title=Merry Xmas 2012 e-card v1.10F type=0 -pokey=true +pokey=1 controller1=1 controller2=0 region=0 @@ -1634,7 +1634,7 @@ flags=0 [eb3c1443f4a25806de4657e106d504e8] title=Meteor Bath (Hack) (RC2) (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1642,16 +1642,16 @@ flags=0 [c3f6201d6a9388e860328c963a3301cc] title=Meteor Shower (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [dc0bf52475030c05671dd187e9a99f08] title=Meteor Shower (PAL) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1659,16 +1659,16 @@ flags=0 [9ff38ea62004201d870caa8bd9463525] title=Moon Cresta (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [675c5b79238eaa641f2e3fe9c5e22589] title=Moon Cresta (PAL) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -1676,7 +1676,7 @@ flags=0 [89f90b661d1b79e956b10bb6a9771f78] title=More Beef Drop (Hack) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1684,34 +1684,34 @@ flags=0 [d8dbb5c4d7d02e6b0627df8f657a13b4] title=Ms Pac-Attack (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [27c133965dfd80b3acb1ed598817aea0] title=Ms Pac-Man (Fast Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [cf007563fe94cacf5ea5295dc93ce9ef] title=Ms Pac-Man (PacManPlus' Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [cad1e733986bce1ee4c9da73de1dcff1] title=Ms Pac-Man Invincible Fast Hack type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1719,7 +1719,7 @@ flags=0 [db768297985178cec034c12a41d6f1a7] title=Ms Pac-Man 320 Invincible NTSC type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1727,16 +1727,16 @@ flags=0 [889fc7e7ba5c807be44e85ba7a6bd26e] title=Ms Pac-Man 320 (NTSC) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [bc56f803d65658f92c17e6c2b271a507] title=Ms. Pac-Man 320 (PAL) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 @@ -1744,16 +1744,16 @@ flags=0 [2a17dc5a61be342dd00af719cc335852] title=Ms Pac-Man 320 Sound Upd NTSC type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [99055c3e627bbc17fc81cbe0b3ae176c] title=Ms Pac-Man 320 Sound Upd PAL type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 @@ -1761,16 +1761,16 @@ flags=0 [a69347c8a681b8e94f79d8d848998007] title=Ms Pac-Man Twin type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [79202cb7d2bc150ffca0c96a4d8b42cf] title=Multi-Lock On type=1 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1778,17 +1778,17 @@ flags=0 [04edf4f3c6b186147c1117359c8f5076] title=Pac Pollux (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 rightswitch=1 -hsc=true +hsc=1 [8338eca612eedf6ddec57d54942863e7] title=Pac-Man (Fast Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1797,7 +1797,7 @@ rightswitch=1 [575c18f77a4215332bf56d0080a234b8] title=Pac-Man (Ferrell's Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1806,26 +1806,26 @@ rightswitch=1 [72ec68627bb7d879ae35a71d7679f71e] title=Pac-Man (PacManPlus' Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 rightswitch=1 -hsc=true +hsc=1 [60982f430b762343d53e48f70acfa6d0] title=Pac-Man 320 (NTSC) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [180121ecb4aabc7daa945b355e15c254] title=Pac-Man 320 (PAL) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 @@ -1833,7 +1833,7 @@ flags=0 [4fb119f6db26380abba03e4ce3ca04c8] title=Pac-Man Christmas 2018 Hack type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1842,7 +1842,7 @@ rightswitch=1 [0b7635d0f39ff97d1e841888e1b23b7b] title=Pac-Man Christmas 2018 Inv Hack type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1851,27 +1851,27 @@ rightswitch=1 [5013b69cb05b21a1194ce48517df7bfc] title=Pac-Man Collection type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=true +pokey450=0 +xm=0 +hsc=1 [6f80cac59023a69afa26182eabbdfbad] title=Pac-Man Collection New Monsters type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [b1685dcbaf1b578cb1b6643666d813e4] title=Pac-Man Collection 2 (Hack) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -1879,7 +1879,7 @@ flags=0 [4748a62d5c628fefd28df5de5567edec] title=Pac-Man Handheld (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1888,7 +1888,7 @@ rightswitch=1 [1d7d65997d7cd0858e9bee71ded272aa] title=Pac-Man Plus (Ferrell's Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1897,55 +1897,55 @@ rightswitch=1 [791e55db03903988280388573a2fcdc1] title=Pac-Man Plus (PacManPlus' Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 rightswitch=1 -hsc=true +hsc=1 [d0bf3b841ad4bbd356e9588874749a13] title=Pac-Man Plus (320 Mode) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=true -xm=true +pokey450=1 +xm=1 [1482beef7dbdb122f6bb4b03640888f2] title=Pac-Man Plus (320 Mode) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 flags=0 -pokey450=true -xm=true +pokey450=1 +xm=1 [8cb66c6ed5b379181b1420d8e4758834] title=Pactron 1984 (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -dualanalog=true +dualanalog=1 [c1ac9987a9483e200c338ccbd2ee94b5] title=Pactron 1984 Extreme (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -dualanalog=true +dualanalog=1 [b5c9f0bf5b5763a923b7f370376b1849] title=Panda Racer type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1953,7 +1953,7 @@ flags=0 [b55e4d255173e5b2c2e620f3186a1ecc] title=PC-Man (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1962,7 +1962,7 @@ rightswitch=1 [26897ab47b8c5d3b57d3cc235d7635d8] title=Chomper (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1971,7 +1971,7 @@ rightswitch=1 [2b1f78aaa2b8de5dae3ee4b93ab678f4] title=Christmas Pac-Man (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1980,7 +1980,7 @@ rightswitch=1 [a3a4dbd27c80eff9bef51f73cd26f1d5] title=Invisible Maze Pac-Man (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1989,7 +1989,7 @@ rightswitch=1 [43a0059ff1b5bf76e0c7023fde7c33a5] title=Jawbreaker (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -1998,7 +1998,7 @@ rightswitch=1 [a8e752d108efceff504ae4edc4766b75] title=Munchkin (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -2007,7 +2007,7 @@ rightswitch=1 [04c985ebbd0bea4c557207e69b8cbd8f] title=Munchman Texas (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -2016,7 +2016,7 @@ rightswitch=1 [bc1f56d7cc14f15ddfcba5e21e19937b] title=YPS Quest (Hack) type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -2026,7 +2026,7 @@ rightswitch=1 [8e0c5fc77b27422a39d86ac2e57dc73d] title=Xmas Time (Hack) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -2034,7 +2034,7 @@ flags=0 [f9fa5107ed213e709858d8876359309e] title=POKEY (Sample) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 @@ -2042,25 +2042,25 @@ flags=0 [2370f7ce1b91fc775bce3e72454f908a] title=Pokey Kong (Hack) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=true +pokey450=1 [b4f137e85588ce42d302102ba7215437] title=Prickle (POKEY Utility) (v09) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=true +pokey450=1 [e1b01dd7e842d2b682ef48f689d5a4eb] title=Rider of the Night type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -2068,26 +2068,26 @@ flags=0 [43525a0405184875c2ecfd0196886a34] title=Rip-Off (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -xm=true -hsc=true +xm=1 +hsc=1 [106b409c6f4c219b1a3b3d099ead3b2b] title=Rip-Off (PAL) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 flags=0 -xm=true +xm=1 [03daa19b7aae2d27e61f2a4dbe3b9b79] title=RMT POKEY Player Test (Demo) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 @@ -2095,25 +2095,25 @@ flags=0 [03935b9a1f2561bada58fcd5d9fd27de] title=Robotron X (NTSC) (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -dualanalog=true +dualanalog=1 [d27ed8f883af9b4ee3b5570f30e9ff71] title=Rowdytron (NTSC) (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -dualanalog=true +dualanalog=1 [01c7bc3cd8375e353c8aa837fe1262ec] title=RPG Player and Map Tiles (Demo) type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -2121,16 +2121,16 @@ flags=0 [a3a85e507d6f718972b1464ce1aaf8a4] title=Scramble type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -xm=true +xm=1 [32f1a1b5a7e3b4493c3b7b637aeea7d8] title=Scrapyard Dog Graphics-Life Hack type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -2138,7 +2138,7 @@ flags=0 [6e27f73bd4a49b647bcd58bc5f8b739d] title=Srapyard Dog (Graphics Hack) type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -2146,7 +2146,7 @@ flags=0 [0070751edb8bbf4dd4a685f58b5b72c5] title=Scrapyard Dog Unlimit Lives Hack type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -2154,16 +2154,16 @@ flags=0 [9bd70c06d3386f76f8162881699a777a] title=Serpentine type=3 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=true +pokey450=1 [95c8a795e30640c9ec82609872c80517] title=Shark Attack (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -2172,7 +2172,7 @@ rightswitch=1 [1c8139c584e1cf5c6afdd2f3455a2446] title=Sky Scraper 2115 type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -2180,7 +2180,7 @@ flags=0 [ca1c27b53fcfb9fed83bc9e92920707c] title=Soft Cell-Tainted Love MusicDemo type=4 -pokey=false +pokey=0 controller1=0 controller2=0 region=0 @@ -2188,16 +2188,16 @@ flags=0 [771cb4609347657f63e6f0eb26036e35] title=Space Duel (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [a84c1b2300fbfbf21b1c02387f613dad] title=Space Duel (PAL) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 @@ -2205,16 +2205,16 @@ flags=0 [6adf79558a3d7f5beca1bb8d34337417] title=Space Invaders (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [0f4bd5800359a62a5874b93dc92a47f1] title=Spire of the Ancients type=2 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 @@ -2222,360 +2222,360 @@ flags=0 [02508e6df5e173b4063a7e6e63295817] title=Super Circus AA-NTSC-Joy-0450 type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=true -xm=true -hsc=true +pokey450=1 +xm=1 +hsc=1 [81cee326b99d6831de10a566e338bd25] title=Super Circus AA-NTSC-joy-4000 type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -hsc=true +hsc=1 [1c9b0bb028e63f83a2d1c1def675acc9] title=Super Circus AA-PAL-Joy-0450 type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 flags=0 -xm=true +xm=1 [f4ad1a1d732c2c8cdbd21dabaf38a46c] title=Super Circus AA-PAL-Joy-4000 type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [f41f651417c234104d37296477fa29eb] title=Super Cobra (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=true +pokey450=0 +xm=0 +hsc=1 [7ab539bb0e99e1e5a1c89230bde64610] title=Super Pac-Man (NTSC) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=true +pokey450=0 +xm=0 +hsc=1 [61aa4a074ad08c524fbee88d15e369ea] title=Super Pac-Man (PAL) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [3632fcc732a33591b91f0eea2c01e599] title=Tank Command-Color Sprite Title type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [d0b87d349d6d5e40920cc4ff95253339] title=Tank Command-Midnight Run Hack type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [9cb3848416e39ebf642357dbee3e5970] title=Tempest (BBC X-Port 1) (v1_00F) type=3 -pokey=false +pokey=0 controller1=1 controller2=0 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [b1ec7bd809ab3deb746c5a5eb2efaecb] title=UFO! type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [43f8e9cec3d9991017709f48a7aa22f6] title=UFO! Genesys (Hack) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [f85d506f5933427c8de664be0c5510a3] title=Ultra Pac-Man (PacManPlus' Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=true +pokey450=0 +xm=0 +hsc=1 [f83849cf3f5ac95856e8f93ee90d5a8d] title=Upside Down Pac-Man (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 rightswitch=1 [c62632545c91823f72f6f14b19766804] title=WarBirds type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [40913dcf24a623c1dc2495a1c4931b48] title=Water Ski - Title Color Realign type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [8b49549763f4f0e42a23942b8df6b248] title=Water Ski-Titl Col Reali Trained type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [7db031f1c4dc957719812fe68ee42531] title=Xevious X (PAL) (Hack) type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [5837c4ac8b481fb98381adfd2fe87969] title=Armor Attack type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=true -hsc=false +pokey450=0 +xm=1 +hsc=0 [05b04e9822a75ceeeaa2eb106ffe768e] title=Adventure Map Demo type=4 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [727b6d447e21af42b3767f9c2cff6012] title=DFHSC78.BIN type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=true +pokey450=0 +xm=0 +hsc=1 [c3107d3e3e17d67e3a11d47a5946a4f3] title=DONKEY KONG XM type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=true +pokey450=0 +xm=0 +hsc=1 [8caa29a8d9214ca02697b3357102309a] title=DONKEY KONG XM type=2 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [b3143adbbb7d7d189e918e5b29d55a72] title=DungeonStalker_Final type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [e547492ebd342e57c28bb235546da299] title=3D Demo type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [89b8b3df46733e0c4d57aeb9bb245e6f] title=Armor Attack II type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [7cdfbe37634e7dcd4dc67db7edbcd3ba] title=Baby Pac-Man type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [1ae0b27d47f19d59652168fad3966375] title=Crazy Otto type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [35433868dfe383ae21fd77507e5a478d] title=Ms. Pac-Man (320 Mode) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=true -hsc=false +pokey450=0 +xm=1 +hsc=0 [59f1c1e7f6653a4e66ea898ce6eab50f] title=Pac-Man Collection! v2 type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=true +pokey450=0 +xm=0 +hsc=1 [c2b42639718d005a6d0aefa0809f77db] title=Pac-Man Collection! v2 type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=1 flags=0 -pokey450=false -xm=false -hsc=false +pokey450=0 +xm=0 +hsc=0 [80ffad3edb50f0970e780a727a4524dd] title=Pac-Man (320 Mode) type=0 -pokey=true +pokey=1 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=true +pokey450=0 +xm=0 +hsc=1 [ff8d8283553af5d5dbdaddb5781b4896] title=Vector Asteroids type=0 -pokey=false +pokey=0 controller1=1 controller2=1 region=0 flags=0 -pokey450=false -xm=false -hsc=true +pokey450=0 +xm=0 +hsc=1 diff --git a/ProSystem.xcodeproj/project.pbxproj b/ProSystem.xcodeproj/project.pbxproj index dd8596d..1b30efb 100644 --- a/ProSystem.xcodeproj/project.pbxproj +++ b/ProSystem.xcodeproj/project.pbxproj @@ -36,32 +36,26 @@ /* Begin PBXBuildFile section */ 82EC409F0FD9EC420017FC19 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 82EC409E0FD9EC420017FC19 /* libz.tbd */; }; - 871EC9A224F08BF700CEC578 /* ExpansionModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 871EC9A124F08BF600CEC578 /* ExpansionModule.cpp */; }; - 8794D9691B74713300897F57 /* Sound.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F59AF17A6189D0005D7EA /* Sound.cpp */; }; + 87664D042956D3C70009C5C1 /* Palette.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CE62956D3C70009C5C1 /* Palette.c */; }; + 87664D052956D3C70009C5C1 /* Memory.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CE82956D3C70009C5C1 /* Memory.c */; }; + 87664D062956D3C70009C5C1 /* Maria.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CE92956D3C70009C5C1 /* Maria.c */; }; + 87664D072956D3C70009C5C1 /* Cartridge.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CEC2956D3C70009C5C1 /* Cartridge.c */; }; + 87664D082956D3C70009C5C1 /* Database.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CED2956D3C70009C5C1 /* Database.c */; }; + 87664D092956D3C70009C5C1 /* Region.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CEF2956D3C70009C5C1 /* Region.c */; }; + 87664D0A2956D3C70009C5C1 /* ExpansionModule.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CF02956D3C70009C5C1 /* ExpansionModule.c */; }; + 87664D0B2956D3C70009C5C1 /* Riot.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CF12956D3C70009C5C1 /* Riot.c */; }; + 87664D0C2956D3C70009C5C1 /* Bios.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CF22956D3C70009C5C1 /* Bios.c */; }; + 87664D0D2956D3C70009C5C1 /* Sally.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CF32956D3C70009C5C1 /* Sally.c */; }; + 87664D0E2956D3C70009C5C1 /* Pokey.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CF52956D3C70009C5C1 /* Pokey.c */; }; + 87664D0F2956D3C70009C5C1 /* Sound.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CF72956D3C70009C5C1 /* Sound.c */; }; + 87664D102956D3C70009C5C1 /* ProSystem.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CF92956D3C70009C5C1 /* ProSystem.c */; }; + 87664D112956D3C70009C5C1 /* Tia.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CFD2956D3C70009C5C1 /* Tia.c */; }; + 87664D122956D3C70009C5C1 /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = 87664CFF2956D3C70009C5C1 /* md5.c */; }; + 87664D142956D46E0009C5C1 /* ProSystem.dat in Resources */ = {isa = PBXBuildFile; fileRef = 87664D132956D46D0009C5C1 /* ProSystem.dat */; }; 8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; }; 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; }; - 941DFB2715B6425200C6552F /* ProSystemGameCore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 941DFB2615B6425200C6552F /* ProSystemGameCore.mm */; }; - 941F59BF17A6189D0005D7EA /* Archive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F598117A6189D0005D7EA /* Archive.cpp */; }; - 941F59C017A6189D0005D7EA /* Bios.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F598317A6189D0005D7EA /* Bios.cpp */; }; - 941F59C117A6189D0005D7EA /* Cartridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F598517A6189D0005D7EA /* Cartridge.cpp */; }; - 941F59C217A6189D0005D7EA /* Common.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F598717A6189D0005D7EA /* Common.cpp */; }; - 941F59C317A6189D0005D7EA /* Database.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F598917A6189D0005D7EA /* Database.cpp */; }; - 941F59C417A6189D0005D7EA /* Hash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F598C17A6189D0005D7EA /* Hash.cpp */; }; - 941F59C617A6189D0005D7EA /* Unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = 941F599417A6189D0005D7EA /* Unzip.c */; }; - 941F59C717A6189D0005D7EA /* Zip.c in Sources */ = {isa = PBXBuildFile; fileRef = 941F599717A6189D0005D7EA /* Zip.c */; }; - 941F59C917A6189D0005D7EA /* Logger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F599B17A6189D0005D7EA /* Logger.cpp */; }; - 941F59CA17A6189D0005D7EA /* Maria.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F599D17A6189D0005D7EA /* Maria.cpp */; }; - 941F59CB17A6189D0005D7EA /* Memory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F599F17A6189D0005D7EA /* Memory.cpp */; }; - 941F59CC17A6189D0005D7EA /* Palette.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F59A217A6189D0005D7EA /* Palette.cpp */; }; - 941F59CD17A6189D0005D7EA /* Pokey.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F59A417A6189D0005D7EA /* Pokey.cpp */; }; - 941F59CE17A6189D0005D7EA /* ProSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F59A617A6189D0005D7EA /* ProSystem.cpp */; }; - 941F59CF17A6189D0005D7EA /* Region.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F59A917A6189D0005D7EA /* Region.cpp */; }; - 941F59D017A6189D0005D7EA /* Riot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F59AB17A6189D0005D7EA /* Riot.cpp */; }; - 941F59D117A6189D0005D7EA /* Sally.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F59AD17A6189D0005D7EA /* Sally.cpp */; }; - 941F59D317A6189D0005D7EA /* Tia.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F59B117A6189D0005D7EA /* Tia.cpp */; }; - 941F59D417A6189D0005D7EA /* Timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941F59B317A6189D0005D7EA /* Timer.cpp */; }; + 941DFB2715B6425200C6552F /* ProSystemGameCore.m in Sources */ = {isa = PBXBuildFile; fileRef = 941DFB2615B6425200C6552F /* ProSystemGameCore.m */; }; 941F59DC17A62ADD0005D7EA /* OpenEmuBase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 941F59DB17A62ADD0005D7EA /* OpenEmuBase.framework */; }; - 941F59FC17A77CC90005D7EA /* ProSystem.dat in Resources */ = {isa = PBXBuildFile; fileRef = 941F59FB17A77CC90005D7EA /* ProSystem.dat */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -99,69 +93,44 @@ 089C167FFE841241C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 82EC409E0FD9EC420017FC19 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; - 871EC9A024F08BF600CEC578 /* ExpansionModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExpansionModule.h; sourceTree = ""; }; - 871EC9A124F08BF600CEC578 /* ExpansionModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExpansionModule.cpp; sourceTree = ""; }; + 87664CE32956D3C70009C5C1 /* Sound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sound.h; sourceTree = ""; }; + 87664CE42956D3C70009C5C1 /* Pokey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pokey.h; sourceTree = ""; }; + 87664CE52956D3C70009C5C1 /* Sally.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sally.h; sourceTree = ""; }; + 87664CE62956D3C70009C5C1 /* Palette.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Palette.c; sourceTree = ""; }; + 87664CE72956D3C70009C5C1 /* Bios.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Bios.h; sourceTree = ""; }; + 87664CE82956D3C70009C5C1 /* Memory.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Memory.c; sourceTree = ""; }; + 87664CE92956D3C70009C5C1 /* Maria.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Maria.c; sourceTree = ""; }; + 87664CEA2956D3C70009C5C1 /* Tia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tia.h; sourceTree = ""; }; + 87664CEB2956D3C70009C5C1 /* ProSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProSystem.h; sourceTree = ""; }; + 87664CEC2956D3C70009C5C1 /* Cartridge.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Cartridge.c; sourceTree = ""; }; + 87664CED2956D3C70009C5C1 /* Database.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Database.c; sourceTree = ""; }; + 87664CEE2956D3C70009C5C1 /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; + 87664CEF2956D3C70009C5C1 /* Region.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Region.c; sourceTree = ""; }; + 87664CF02956D3C70009C5C1 /* ExpansionModule.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ExpansionModule.c; sourceTree = ""; }; + 87664CF12956D3C70009C5C1 /* Riot.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Riot.c; sourceTree = ""; }; + 87664CF22956D3C70009C5C1 /* Bios.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Bios.c; sourceTree = ""; }; + 87664CF32956D3C70009C5C1 /* Sally.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Sally.c; sourceTree = ""; }; + 87664CF42956D3C70009C5C1 /* Palette.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Palette.h; sourceTree = ""; }; + 87664CF52956D3C70009C5C1 /* Pokey.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Pokey.c; sourceTree = ""; }; + 87664CF62956D3C70009C5C1 /* Rect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Rect.h; sourceTree = ""; }; + 87664CF72956D3C70009C5C1 /* Sound.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Sound.c; sourceTree = ""; }; + 87664CF82956D3C70009C5C1 /* Database.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Database.h; sourceTree = ""; }; + 87664CF92956D3C70009C5C1 /* ProSystem.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ProSystem.c; sourceTree = ""; }; + 87664CFA2956D3C70009C5C1 /* Cartridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cartridge.h; sourceTree = ""; }; + 87664CFB2956D3C70009C5C1 /* Pair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pair.h; sourceTree = ""; }; + 87664CFC2956D3C70009C5C1 /* Maria.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Maria.h; sourceTree = ""; }; + 87664CFD2956D3C70009C5C1 /* Tia.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Tia.c; sourceTree = ""; }; + 87664CFE2956D3C70009C5C1 /* Memory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Memory.h; sourceTree = ""; }; + 87664CFF2956D3C70009C5C1 /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5.c; sourceTree = ""; }; + 87664D002956D3C70009C5C1 /* Region.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Region.h; sourceTree = ""; }; + 87664D012956D3C70009C5C1 /* ExpansionModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExpansionModule.h; sourceTree = ""; }; + 87664D022956D3C70009C5C1 /* Riot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Riot.h; sourceTree = ""; }; + 87664D032956D3C70009C5C1 /* Equates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Equates.h; sourceTree = ""; }; + 87664D132956D46D0009C5C1 /* ProSystem.dat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ProSystem.dat; sourceTree = ""; }; 8D5B49B6048680CD000E48DA /* ProSystem.oecoreplugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ProSystem.oecoreplugin; sourceTree = BUILT_PRODUCTS_DIR; }; 8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 941DFB2615B6425200C6552F /* ProSystemGameCore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ProSystemGameCore.mm; sourceTree = ""; }; - 941F598117A6189D0005D7EA /* Archive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Archive.cpp; sourceTree = ""; }; - 941F598217A6189D0005D7EA /* Archive.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Archive.h; sourceTree = ""; }; - 941F598317A6189D0005D7EA /* Bios.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Bios.cpp; sourceTree = ""; }; - 941F598417A6189D0005D7EA /* Bios.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Bios.h; sourceTree = ""; }; - 941F598517A6189D0005D7EA /* Cartridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Cartridge.cpp; sourceTree = ""; }; - 941F598617A6189D0005D7EA /* Cartridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cartridge.h; sourceTree = ""; }; - 941F598717A6189D0005D7EA /* Common.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Common.cpp; sourceTree = ""; }; - 941F598817A6189D0005D7EA /* Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Common.h; sourceTree = ""; }; - 941F598917A6189D0005D7EA /* Database.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Database.cpp; sourceTree = ""; }; - 941F598A17A6189D0005D7EA /* Database.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Database.h; sourceTree = ""; }; - 941F598B17A6189D0005D7EA /* Equates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Equates.h; sourceTree = ""; }; - 941F598C17A6189D0005D7EA /* Hash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Hash.cpp; sourceTree = ""; }; - 941F598D17A6189D0005D7EA /* Hash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Hash.h; sourceTree = ""; }; - 941F598F17A6189D0005D7EA /* Crypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Crypt.h; sourceTree = ""; }; - 941F599017A6189D0005D7EA /* HtmlHelp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HtmlHelp.h; sourceTree = ""; }; - 941F599217A6189D0005D7EA /* Ioapi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Ioapi.h; sourceTree = ""; }; - 941F599317A6189D0005D7EA /* miniunz.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = miniunz.h; sourceTree = ""; }; - 941F599417A6189D0005D7EA /* Unzip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Unzip.c; sourceTree = ""; }; - 941F599517A6189D0005D7EA /* unzip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unzip.h; sourceTree = ""; }; - 941F599617A6189D0005D7EA /* Zconf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Zconf.h; sourceTree = ""; }; - 941F599717A6189D0005D7EA /* Zip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Zip.c; sourceTree = ""; }; - 941F599817A6189D0005D7EA /* Zip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Zip.h; sourceTree = ""; }; - 941F599917A6189D0005D7EA /* Zlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Zlib.h; sourceTree = ""; }; - 941F599B17A6189D0005D7EA /* Logger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Logger.cpp; sourceTree = ""; }; - 941F599C17A6189D0005D7EA /* Logger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Logger.h; sourceTree = ""; }; - 941F599D17A6189D0005D7EA /* Maria.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Maria.cpp; sourceTree = ""; }; - 941F599E17A6189D0005D7EA /* Maria.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Maria.h; sourceTree = ""; }; - 941F599F17A6189D0005D7EA /* Memory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Memory.cpp; sourceTree = ""; }; - 941F59A017A6189D0005D7EA /* Memory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Memory.h; sourceTree = ""; }; - 941F59A117A6189D0005D7EA /* Pair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pair.h; sourceTree = ""; }; - 941F59A217A6189D0005D7EA /* Palette.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Palette.cpp; sourceTree = ""; }; - 941F59A317A6189D0005D7EA /* Palette.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Palette.h; sourceTree = ""; }; - 941F59A417A6189D0005D7EA /* Pokey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Pokey.cpp; sourceTree = ""; }; - 941F59A517A6189D0005D7EA /* Pokey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pokey.h; sourceTree = ""; }; - 941F59A617A6189D0005D7EA /* ProSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProSystem.cpp; sourceTree = ""; }; - 941F59A717A6189D0005D7EA /* ProSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProSystem.h; sourceTree = ""; }; - 941F59A817A6189D0005D7EA /* Rect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Rect.h; sourceTree = ""; }; - 941F59A917A6189D0005D7EA /* Region.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Region.cpp; sourceTree = ""; }; - 941F59AA17A6189D0005D7EA /* Region.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Region.h; sourceTree = ""; }; - 941F59AB17A6189D0005D7EA /* Riot.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Riot.cpp; sourceTree = ""; }; - 941F59AC17A6189D0005D7EA /* Riot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Riot.h; sourceTree = ""; }; - 941F59AD17A6189D0005D7EA /* Sally.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Sally.cpp; sourceTree = ""; }; - 941F59AE17A6189D0005D7EA /* Sally.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sally.h; sourceTree = ""; }; - 941F59AF17A6189D0005D7EA /* Sound.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Sound.cpp; sourceTree = ""; }; - 941F59B017A6189D0005D7EA /* Sound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sound.h; sourceTree = ""; }; - 941F59B117A6189D0005D7EA /* Tia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Tia.cpp; sourceTree = ""; }; - 941F59B217A6189D0005D7EA /* Tia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tia.h; sourceTree = ""; }; - 941F59B317A6189D0005D7EA /* Timer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Timer.cpp; sourceTree = ""; }; - 941F59B417A6189D0005D7EA /* Timer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Timer.h; sourceTree = ""; }; - 941F59B617A6189D0005D7EA /* Crypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Crypt.h; sourceTree = ""; }; - 941F59B717A6189D0005D7EA /* HtmlHelp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HtmlHelp.h; sourceTree = ""; }; - 941F59B917A6189D0005D7EA /* Ioapi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Ioapi.h; sourceTree = ""; }; - 941F59BA17A6189D0005D7EA /* Unzip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unzip.h; sourceTree = ""; }; - 941F59BB17A6189D0005D7EA /* Zconf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Zconf.h; sourceTree = ""; }; - 941F59BC17A6189D0005D7EA /* Zip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Zip.h; sourceTree = ""; }; - 941F59BD17A6189D0005D7EA /* Zlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Zlib.h; sourceTree = ""; }; + 941DFB2615B6425200C6552F /* ProSystemGameCore.m */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = ProSystemGameCore.m; sourceTree = ""; }; 941F59DB17A62ADD0005D7EA /* OpenEmuBase.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = OpenEmuBase.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 941F59FB17A77CC90005D7EA /* ProSystem.dat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ProSystem.dat; sourceTree = SOURCE_ROOT; }; 941F5A2617A78FF20005D7EA /* OE7800SystemResponderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OE7800SystemResponderClient.h; path = "../OpenEmu/SystemPlugins/Atari 7800/OE7800SystemResponderClient.h"; sourceTree = ""; }; B5008DAD0E8BFB3E005AECAF /* ProSystemGameCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProSystemGameCore.h; sourceTree = ""; }; D2F7E65807B2D6F200F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; @@ -184,9 +153,8 @@ 089C166AFE841209C02AAC07 /* VisualBoyAdvance */ = { isa = PBXGroup; children = ( - 94A9E27F157D637B0083A7DC /* Core */, + 87664CE12956D3B70009C5C1 /* Core */, 08FB77AFFE84173DC02AAC07 /* Classes */, - 32C88E010371C26100C91783 /* Other Sources */, 089C167CFE841241C02AAC07 /* Resources */, 089C1671FE841209C02AAC07 /* Frameworks */, 19C28FB8FE9D52D311CA2CBB /* Products */, @@ -210,6 +178,7 @@ children = ( 8D5B49B7048680CD000E48DA /* Info.plist */, 089C167DFE841241C02AAC07 /* InfoPlist.strings */, + 87664D132956D46D0009C5C1 /* ProSystem.dat */, ); name = Resources; sourceTree = ""; @@ -219,7 +188,7 @@ children = ( 941F5A2617A78FF20005D7EA /* OE7800SystemResponderClient.h */, B5008DAD0E8BFB3E005AECAF /* ProSystemGameCore.h */, - 941DFB2615B6425200C6552F /* ProSystemGameCore.mm */, + 941DFB2615B6425200C6552F /* ProSystemGameCore.m */, ); name = Classes; sourceTree = ""; @@ -251,103 +220,52 @@ name = Products; sourceTree = ""; }; - 32C88E010371C26100C91783 /* Other Sources */ = { + 87664CE12956D3B70009C5C1 /* Core */ = { isa = PBXGroup; children = ( + 87664CE22956D3C70009C5C1 /* src */, ); - name = "Other Sources"; + name = Core; sourceTree = ""; }; - 941F598017A6189D0005D7EA /* core */ = { + 87664CE22956D3C70009C5C1 /* src */ = { isa = PBXGroup; children = ( - 941F598117A6189D0005D7EA /* Archive.cpp */, - 941F598217A6189D0005D7EA /* Archive.h */, - 941F598317A6189D0005D7EA /* Bios.cpp */, - 941F598417A6189D0005D7EA /* Bios.h */, - 941F598517A6189D0005D7EA /* Cartridge.cpp */, - 941F598617A6189D0005D7EA /* Cartridge.h */, - 941F598717A6189D0005D7EA /* Common.cpp */, - 941F598817A6189D0005D7EA /* Common.h */, - 941F598917A6189D0005D7EA /* Database.cpp */, - 941F598A17A6189D0005D7EA /* Database.h */, - 941F598B17A6189D0005D7EA /* Equates.h */, - 871EC9A124F08BF600CEC578 /* ExpansionModule.cpp */, - 871EC9A024F08BF600CEC578 /* ExpansionModule.h */, - 941F598C17A6189D0005D7EA /* Hash.cpp */, - 941F598D17A6189D0005D7EA /* Hash.h */, - 941F598E17A6189D0005D7EA /* lib */, - 941F599B17A6189D0005D7EA /* Logger.cpp */, - 941F599C17A6189D0005D7EA /* Logger.h */, - 941F599D17A6189D0005D7EA /* Maria.cpp */, - 941F599E17A6189D0005D7EA /* Maria.h */, - 941F599F17A6189D0005D7EA /* Memory.cpp */, - 941F59A017A6189D0005D7EA /* Memory.h */, - 941F59A117A6189D0005D7EA /* Pair.h */, - 941F59A217A6189D0005D7EA /* Palette.cpp */, - 941F59A317A6189D0005D7EA /* Palette.h */, - 941F59A417A6189D0005D7EA /* Pokey.cpp */, - 941F59A517A6189D0005D7EA /* Pokey.h */, - 941F59A617A6189D0005D7EA /* ProSystem.cpp */, - 941F59A717A6189D0005D7EA /* ProSystem.h */, - 941F59A817A6189D0005D7EA /* Rect.h */, - 941F59A917A6189D0005D7EA /* Region.cpp */, - 941F59AA17A6189D0005D7EA /* Region.h */, - 941F59AB17A6189D0005D7EA /* Riot.cpp */, - 941F59AC17A6189D0005D7EA /* Riot.h */, - 941F59AD17A6189D0005D7EA /* Sally.cpp */, - 941F59AE17A6189D0005D7EA /* Sally.h */, - 941F59AF17A6189D0005D7EA /* Sound.cpp */, - 941F59B017A6189D0005D7EA /* Sound.h */, - 941F59B117A6189D0005D7EA /* Tia.cpp */, - 941F59B217A6189D0005D7EA /* Tia.h */, - 941F59B317A6189D0005D7EA /* Timer.cpp */, - 941F59B417A6189D0005D7EA /* Timer.h */, + 87664CF22956D3C70009C5C1 /* Bios.c */, + 87664CE72956D3C70009C5C1 /* Bios.h */, + 87664CEC2956D3C70009C5C1 /* Cartridge.c */, + 87664CFA2956D3C70009C5C1 /* Cartridge.h */, + 87664CED2956D3C70009C5C1 /* Database.c */, + 87664CF82956D3C70009C5C1 /* Database.h */, + 87664D032956D3C70009C5C1 /* Equates.h */, + 87664CF02956D3C70009C5C1 /* ExpansionModule.c */, + 87664D012956D3C70009C5C1 /* ExpansionModule.h */, + 87664CE92956D3C70009C5C1 /* Maria.c */, + 87664CFC2956D3C70009C5C1 /* Maria.h */, + 87664CFF2956D3C70009C5C1 /* md5.c */, + 87664CEE2956D3C70009C5C1 /* md5.h */, + 87664CE82956D3C70009C5C1 /* Memory.c */, + 87664CFE2956D3C70009C5C1 /* Memory.h */, + 87664CFB2956D3C70009C5C1 /* Pair.h */, + 87664CE62956D3C70009C5C1 /* Palette.c */, + 87664CF42956D3C70009C5C1 /* Palette.h */, + 87664CF52956D3C70009C5C1 /* Pokey.c */, + 87664CE42956D3C70009C5C1 /* Pokey.h */, + 87664CF92956D3C70009C5C1 /* ProSystem.c */, + 87664CEB2956D3C70009C5C1 /* ProSystem.h */, + 87664CF62956D3C70009C5C1 /* Rect.h */, + 87664CEF2956D3C70009C5C1 /* Region.c */, + 87664D002956D3C70009C5C1 /* Region.h */, + 87664CF12956D3C70009C5C1 /* Riot.c */, + 87664D022956D3C70009C5C1 /* Riot.h */, + 87664CF32956D3C70009C5C1 /* Sally.c */, + 87664CE52956D3C70009C5C1 /* Sally.h */, + 87664CF72956D3C70009C5C1 /* Sound.c */, + 87664CE32956D3C70009C5C1 /* Sound.h */, + 87664CFD2956D3C70009C5C1 /* Tia.c */, + 87664CEA2956D3C70009C5C1 /* Tia.h */, ); - indentWidth = 2; - path = core; - sourceTree = SOURCE_ROOT; - }; - 941F598E17A6189D0005D7EA /* lib */ = { - isa = PBXGroup; - children = ( - 941F598F17A6189D0005D7EA /* Crypt.h */, - 941F599017A6189D0005D7EA /* HtmlHelp.h */, - 941F599217A6189D0005D7EA /* Ioapi.h */, - 941F599317A6189D0005D7EA /* miniunz.h */, - 941F599417A6189D0005D7EA /* Unzip.c */, - 941F599517A6189D0005D7EA /* unzip.h */, - 941F599617A6189D0005D7EA /* Zconf.h */, - 941F599717A6189D0005D7EA /* Zip.c */, - 941F599817A6189D0005D7EA /* Zip.h */, - 941F599917A6189D0005D7EA /* Zlib.h */, - ); - indentWidth = 4; - path = lib; - sourceTree = ""; - }; - 941F59B517A6189D0005D7EA /* Lib */ = { - isa = PBXGroup; - children = ( - 941F59B617A6189D0005D7EA /* Crypt.h */, - 941F59B717A6189D0005D7EA /* HtmlHelp.h */, - 941F59B917A6189D0005D7EA /* Ioapi.h */, - 941F59BA17A6189D0005D7EA /* Unzip.h */, - 941F59BB17A6189D0005D7EA /* Zconf.h */, - 941F59BC17A6189D0005D7EA /* Zip.h */, - 941F59BD17A6189D0005D7EA /* Zlib.h */, - ); - path = Lib; - sourceTree = SOURCE_ROOT; - }; - 94A9E27F157D637B0083A7DC /* Core */ = { - isa = PBXGroup; - children = ( - 941F59FB17A77CC90005D7EA /* ProSystem.dat */, - 941F598017A6189D0005D7EA /* core */, - 941F59B517A6189D0005D7EA /* Lib */, - ); - path = Core; + path = src; sourceTree = ""; }; /* End PBXGroup section */ @@ -403,7 +321,7 @@ buildActionMask = 2147483647; files = ( 8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */, - 941F59FC17A77CC90005D7EA /* ProSystem.dat in Resources */, + 87664D142956D46E0009C5C1 /* ProSystem.dat in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -443,28 +361,22 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8794D9691B74713300897F57 /* Sound.cpp in Sources */, - 941DFB2715B6425200C6552F /* ProSystemGameCore.mm in Sources */, - 941F59BF17A6189D0005D7EA /* Archive.cpp in Sources */, - 941F59C017A6189D0005D7EA /* Bios.cpp in Sources */, - 941F59C117A6189D0005D7EA /* Cartridge.cpp in Sources */, - 941F59C217A6189D0005D7EA /* Common.cpp in Sources */, - 941F59C317A6189D0005D7EA /* Database.cpp in Sources */, - 941F59C417A6189D0005D7EA /* Hash.cpp in Sources */, - 941F59C617A6189D0005D7EA /* Unzip.c in Sources */, - 941F59C717A6189D0005D7EA /* Zip.c in Sources */, - 941F59C917A6189D0005D7EA /* Logger.cpp in Sources */, - 941F59CA17A6189D0005D7EA /* Maria.cpp in Sources */, - 941F59CB17A6189D0005D7EA /* Memory.cpp in Sources */, - 941F59CC17A6189D0005D7EA /* Palette.cpp in Sources */, - 941F59CD17A6189D0005D7EA /* Pokey.cpp in Sources */, - 941F59CE17A6189D0005D7EA /* ProSystem.cpp in Sources */, - 941F59CF17A6189D0005D7EA /* Region.cpp in Sources */, - 871EC9A224F08BF700CEC578 /* ExpansionModule.cpp in Sources */, - 941F59D017A6189D0005D7EA /* Riot.cpp in Sources */, - 941F59D117A6189D0005D7EA /* Sally.cpp in Sources */, - 941F59D317A6189D0005D7EA /* Tia.cpp in Sources */, - 941F59D417A6189D0005D7EA /* Timer.cpp in Sources */, + 941DFB2715B6425200C6552F /* ProSystemGameCore.m in Sources */, + 87664D0C2956D3C70009C5C1 /* Bios.c in Sources */, + 87664D072956D3C70009C5C1 /* Cartridge.c in Sources */, + 87664D082956D3C70009C5C1 /* Database.c in Sources */, + 87664D0A2956D3C70009C5C1 /* ExpansionModule.c in Sources */, + 87664D062956D3C70009C5C1 /* Maria.c in Sources */, + 87664D122956D3C70009C5C1 /* md5.c in Sources */, + 87664D052956D3C70009C5C1 /* Memory.c in Sources */, + 87664D042956D3C70009C5C1 /* Palette.c in Sources */, + 87664D0E2956D3C70009C5C1 /* Pokey.c in Sources */, + 87664D102956D3C70009C5C1 /* ProSystem.c in Sources */, + 87664D092956D3C70009C5C1 /* Region.c in Sources */, + 87664D0B2956D3C70009C5C1 /* Riot.c in Sources */, + 87664D0D2956D3C70009C5C1 /* Sally.c in Sources */, + 87664D0F2956D3C70009C5C1 /* Sound.c in Sources */, + 87664D112956D3C70009C5C1 /* Tia.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ProSystemGameCore.mm b/ProSystemGameCore.m similarity index 90% rename from ProSystemGameCore.mm rename to ProSystemGameCore.m index 72ebd8c..d7ea679 100644 --- a/ProSystemGameCore.mm +++ b/ProSystemGameCore.m @@ -89,10 +89,12 @@ // Right difficulty switch defaults to right position, "(A)dvanced", which fixes Tower Toppler _inputState[RIGHT_DIFF_SWITCH] = RIGHT_POSITION; - if(cartridge_Load(path.fileSystemRepresentation)) + NSData *romData = [NSData dataWithContentsOfFile:path]; + + if(cartridge_Load((const uint8_t*)romData.bytes, (uint32_t)romData.length)) { - NSString *databasePath = [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"ProSystem.dat"]; - database_filename = databasePath.fileSystemRepresentation; + NSURL *databaseURL = [self.owner.bundle URLForResource:@"ProSystem" withExtension:@"dat"]; + database_filename = databaseURL.fileSystemRepresentation; database_enabled = true; // BIOS is optional @@ -100,15 +102,14 @@ if (bios_Load(biosROM.fileSystemRepresentation)) bios_enabled = true; - NSLog(@"[ProSystem] Headerless MD5 hash: %s", cartridge_digest.c_str()); - NSLog(@"[ProSystem] Header info (often wrong):\ntitle: %s\ntype: %d\nregion: %s\npokey: %s", cartridge_title.c_str(), cartridge_type, cartridge_region == REGION_NTSC ? "NTSC" : "PAL", cartridge_pokey ? "true" : "false"); + NSLog(@"[ProSystem] Headerless MD5 hash: %s", cart_digest); + NSLog(@"[ProSystem] Header info (often wrong):\ntitle: %s\ntype: %d\nregion: %s\npokey: %s", cartridge_title, cartridge_type, cartridge_region == REGION_NTSC ? "NTSC" : "PAL", cartridge_pokey ? "true" : "false"); - database_Load(cartridge_digest); + database_Load(cart_digest); prosystem_Reset(); if (cart_in_db) { - std::string title = common_Trim(cartridge_title); - NSLog(@"[ProSystem] Database info:\ntitle: %@\ntype: %d\nregion: %s\npokey: %s", [NSString stringWithUTF8String:title.c_str()], cartridge_type, cartridge_region == REGION_NTSC ? "NTSC" : "PAL", cartridge_pokey ? "true" : "false"); + NSLog(@"[ProSystem] Database info:\ntitle: %@\ntype: %d\nregion: %s\npokey: %s", [[NSString stringWithUTF8String:cartridge_title] stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet], cartridge_type, cartridge_region == REGION_NTSC ? "NTSC" : "PAL", cartridge_pokey ? "true" : "false"); } //sound_SetSampleRate(48000); @@ -133,10 +134,10 @@ { prosystem_ExecuteFrame(_inputState); - _videoWidth = maria_visibleArea.GetLength(); - _videoHeight = maria_visibleArea.GetHeight(); + _videoWidth = ((maria_displayArea.right - maria_displayArea.left) + 1); + _videoHeight = ((maria_visibleArea.bottom - maria_visibleArea.top) + 1); - uint8_t *buffer = maria_surface + ((maria_visibleArea.top - maria_displayArea.top) * maria_visibleArea.GetLength()); + uint8_t *buffer = maria_surface + ((maria_visibleArea.top - maria_displayArea.top) * _videoWidth); uint32_t *surface = (uint32_t *)_videoBuffer; int pitch = 320; @@ -154,7 +155,7 @@ } int length = sound_Store(_soundBuffer); - [[self ringBufferAtIndex:0] write:_soundBuffer maxLength:length]; + [[self audioBufferAtIndex:0] write:_soundBuffer maxLength:length]; } - (void)resetEmulation @@ -176,12 +177,12 @@ - (OEIntRect)screenRect { - return OEIntRectMake(0, 0, maria_visibleArea.GetLength(), maria_visibleArea.GetHeight()); + return OEIntRectMake(0, 0, _videoWidth, _videoHeight); } - (OEIntSize)aspectSize { - return OEIntSizeMake(maria_visibleArea.GetLength(), maria_visibleArea.GetHeight()); + return OEIntSizeMake(_videoWidth, _videoHeight); } - (OEIntSize)bufferSize @@ -220,7 +221,7 @@ - (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block { - block(prosystem_Save(fileName.fileSystemRepresentation, false) ? YES : NO, nil); + block(prosystem_Save(fileName.fileSystemRepresentation) ? YES : NO, nil); } - (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)(BOOL, NSError *))block diff --git a/README b/README new file mode 100644 index 0000000..eb7edf4 --- /dev/null +++ b/README @@ -0,0 +1,40 @@ +ProSystem JG +------------ +ProSystem JG is an emulator for the Atari 7800. + +This is a fork of ProSystem 1.3e with patches from OpenEmu, which contains +patches derived from Wii7800 and js7800. + +The code has been significantly altered. It was ported from C++ to C, and +all of the dependencies and Windows-specific code were removed. + +This repository lives at https://gitlab.com/jgemu/prosystem + +Compiling +--------- +Make sure you have The Jolly Good API's header files installed. If you did +not install them, you will be required to include their path in CFLAGS. + +Linux: + make + +macOS: + make + +BSD: + gmake + +Windows (MSYS2): + make + +The build will be output to "prosystem/". This directory may be used as is +locally by copying it to your local "cores" directory, or may be installed +system-wide using the "install" target specified in the Makefile. + +Input Devices +------------- +ProSystem JG uses a game database to determine which input devices must be +plugged in. The following input devices are currently supported: + +7800 Joystick +XG-1 Light Gun diff --git a/Win/About.cpp b/Win/About.cpp deleted file mode 100755 index 9df6ed2..0000000 --- a/Win/About.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// About.cpp -// ---------------------------------------------------------------------------- -#include "About.h" - -// ---------------------------------------------------------------------------- -// Procedure -// ---------------------------------------------------------------------------- -static BOOL CALLBACK about_Procedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - if(message == WM_INITDIALOG) { - HWND hStaticVersion = GetDlgItem(hWnd, IDC_STATIC_VERSION2); - std::string versionText = "Version " + common_Format(CONSOLE_VERSION, "%1.1f"); - SetWindowText(hStaticVersion, versionText.c_str( )); - } - else if(message == WM_COMMAND) { - if(LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDC_BUTTON_ABOUT_OK) { - EndDialog(hWnd, 0); - return 1; - } - } - return 0; -} - -// ---------------------------------------------------------------------------- -// Show -// ---------------------------------------------------------------------------- -void about_Show(HWND hWnd, HINSTANCE hInstance) { - DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_ABOUT), hWnd, (DLGPROC)about_Procedure); -} \ No newline at end of file diff --git a/Win/About.h b/Win/About.h deleted file mode 100755 index 48e6592..0000000 --- a/Win/About.h +++ /dev/null @@ -1,39 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// About.h -// ---------------------------------------------------------------------------- -#ifndef ABOUT_H -#define ABOUT_H - -#include -#include "Resource.h" -#include "Common.h" -#include "Console.h" - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern void about_Show(HWND hWnd, HINSTANCE hInstance); - -#endif \ No newline at end of file diff --git a/Win/Common.cpp b/Win/Common.cpp deleted file mode 100755 index 0537ba5..0000000 --- a/Win/Common.cpp +++ /dev/null @@ -1,216 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Common.cpp -// ---------------------------------------------------------------------------- -#include "Common.h" - -std::string common_defaultPath; - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(double value) { - return common_Format(value, "%f"); -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(double value, std::string specification) { - char buffer[17] = {0}; - sprintf(buffer, specification.c_str( ), value); - return std::string(buffer); -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(uint value) { - char buffer[11] = {0}; - sprintf(buffer, "%d", value); - return std::string(buffer); -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(word value) { - char buffer[6] = {0}; - sprintf(buffer, "%d", value); - return std::string(buffer); -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(byte value) { - char buffer[4] = {0}; - sprintf(buffer, "%d", value); - return std::string(buffer); -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(bool value) { - return (value)? "true": "false"; -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(HRESULT result) { - char buffer[10] = {0}; - sprintf(buffer, "%#8x", result); - return std::string(buffer); -} - -// ---------------------------------------------------------------------------- -// ParseUint -// ---------------------------------------------------------------------------- -uint common_ParseUint(std::string text) { - return (uint)atoi(text.c_str( )); -} - -// ---------------------------------------------------------------------------- -// ParseWord -// ---------------------------------------------------------------------------- -word common_ParseWord(std::string text) { - return (word)atoi(text.c_str( )); -} - -// ---------------------------------------------------------------------------- -// ParseByte -// ---------------------------------------------------------------------------- -byte common_ParseByte(std::string text) { - return (byte)atoi(text.c_str( )); -} - -// ---------------------------------------------------------------------------- -// ParseBool -// ---------------------------------------------------------------------------- -bool common_ParseBool(std::string text) { - if(text.compare("true") == 0 || text.compare("TRUE") == 0 || text.compare("True") == 0) { - return true; - } - if(atoi(text.c_str( )) == 1) { - return true; - } - return false; -} - -// ---------------------------------------------------------------------------- -// Trim -// ---------------------------------------------------------------------------- -std::string common_Trim(std::string target) { - int index; - for(index = target.length( ) - 1; index >= 0; index--) { - if(target[index] != 0x20 && target[index] != '\n') { - break; - } - } - return target.substr(0, index + 1); -} - -// ---------------------------------------------------------------------------- -// Remove -// ---------------------------------------------------------------------------- -std::string common_Remove(std::string target, char value) { - int length = 0; - int index; - for(index = 0; index < target.size( ); index++) { - if(target[index] != value) { - length++; - } - } - - char* buffer = new char[length + 1]; - int count = 0; - for(index = 0; index < target.size( ); index++) { - if(target[index] != value) { - buffer[count] = target[index]; - count++; - } - } - - buffer[length] = 0; - std::string source = buffer; - delete[ ] buffer; - return source; -} - -// ---------------------------------------------------------------------------- -// Replace (string, from, to) -// ---------------------------------------------------------------------------- -std::string common_Replace(std::string target, char value1, char value2) { - int length = 0; - int index; - for(index = 0; index < target.size( ); index++) { - length++; - } - - char* buffer = new char[length + 1]; - for(index = 0; index < target.size( ); index++) { - if(target[index] != value1) { - buffer[index] = target[index]; - } - else - { - buffer[index] = value2; - } - } - - buffer[length] = 0; - std::string source = buffer; - delete[ ] buffer; - return source; -} - -// ---------------------------------------------------------------------------- -// GetErrorMessage -// ---------------------------------------------------------------------------- -std::string common_GetErrorMessage( ) { - return common_GetErrorMessage(GetLastError( )); -} - -// ---------------------------------------------------------------------------- -// GetErrorMessage -// ---------------------------------------------------------------------------- -std::string common_GetErrorMessage(DWORD error) { - void* buffer; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buffer, 0, NULL); - std::string message((char*)buffer); - LocalFree(buffer); - return message; -} - -// ---------------------------------------------------------------------------- -// GetExtension -// ---------------------------------------------------------------------------- -std::string common_GetExtension(std::string filename) { - int position = filename.rfind('.'); - if(position != -1) { - return filename.substr(position); - } - return ""; -} diff --git a/Win/Common.h b/Win/Common.h deleted file mode 100755 index db92379..0000000 --- a/Win/Common.h +++ /dev/null @@ -1,54 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Common.h -// ---------------------------------------------------------------------------- -#ifndef COMMON_H -#define COMMON_H - -#include -#include - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern std::string common_Format(double value); -extern std::string common_Format(double value, std::string specification); -extern std::string common_Format(uint value); -extern std::string common_Format(word value); -extern std::string common_Format(byte value); -extern std::string common_Format(bool value); -extern std::string common_Format(HRESULT result); -extern std::string common_Trim(std::string target); -extern std::string common_Remove(std::string target, char value); -extern std::string common_Replace(std::string target, char value1, char value2); -extern std::string common_GetErrorMessage( ); -extern std::string common_GetErrorMessage(DWORD error); -extern std::string common_GetExtension(std::string filename); -extern uint common_ParseUint(std::string text); -extern word common_ParseWord(std::string text); -extern byte common_ParseByte(std::string text); -extern bool common_ParseBool(std::string text); -extern std::string common_defaultPath; - -#endif diff --git a/Win/Configuration.cpp b/Win/Configuration.cpp deleted file mode 100755 index eed3b5a..0000000 --- a/Win/Configuration.cpp +++ /dev/null @@ -1,317 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Configuration.cpp -// ---------------------------------------------------------------------------- -#include "Configuration.h" -#include "Console.h" - - -bool configuration_enabled = true; -bool screenshot1=false; -bool screenshot2=false; -uint samplerate; - - -static const std::string CONFIGURATION_SECTION_CONSOLE = "Console"; -static const std::string CONFIGURATION_SECTION_RECENT = "Recent"; -static const std::string CONFIGURATION_SECTION_DISPLAY = "Display"; -static const std::string CONFIGURATION_SECTION_SOUND = "Sound"; -static const std::string CONFIGURATION_SECTION_EMULATION = "Emulation"; -static const std::string CONFIGURATION_SECTION_INPUT = "Input"; - -static std::string configuration_filename; - -// ---------------------------------------------------------------------------- -// CommandLine -// ---------------------------------------------------------------------------- -std::string configuration_CommandLine(std::string commandLine) { - char **argv; - int argc,i; - std::string tmp_string; - - argc = __argc; - argv = __argv; - for ( i = 1; i < argc; ++i ) { - if ( strstr(argv[i],"-Fullscreen") || strstr(argv[i],"-fullscreen") ) { - if ( ++i < argc ) { - if ( atoi(argv[i]) ) - display_fullscreen = true; - else - display_fullscreen = false; - } - } - - else if ( strstr(argv[i],"-MenuEnabled") || strstr(argv[i],"-menuenabled") ) { - if ( ++i < argc ) { - if ( atoi(argv[i]) ) - display_menuenabled = true; - else - display_menuenabled = false; - } - } - - else if ( strstr(argv[i],"-Palette") || strstr(argv[i],"-palette") ) { - if ( ++i < argc ) { - tmp_string = argv[i]; - palette_default = false; - palette_Load(common_Remove(tmp_string,'"')); - } - } - - else if ( strstr(argv[i],"-Zoom") || strstr(argv[i],"-zoom") ) { - if ( ++i < argc ) { - display_zoom = atoi(argv[i]); - } - } - - else if ( strstr(argv[i],"-Mute") || strstr(argv[i],"-mute") ) { - if ( ++i < argc ) { - if ( atoi(argv[i]) ) - sound_SetMuted(true); - else - sound_SetMuted(false); - } - } - - else if ( strstr(argv[i],"-Latency") || strstr(argv[i],"-latency") ) { - if ( ++i < argc ) { - sound_latency = atoi(argv[i]); - } - } - - else if ( strstr(argv[i],"-SampleRate") || strstr(argv[i],"-samplerate") ) { - if ( ++i < argc ) { - sound_SetSampleRate ( atoi(argv[i]) ); - samplerate=atoi(argv[i]); - } - } - - else if ( strstr(argv[i],"-Region") || strstr(argv[i],"-region") ) { - if ( ++i < argc ) { - if ( strstr(argv[i],"PAL") ) - region_type = REGION_PAL; - else if ( strstr(argv[i],"NTSC") ) - region_type = REGION_NTSC; - else - region_type = REGION_AUTO; - } - } - - else { - return tmp_string = argv[i]; - } - - } /* end for each argument */ - menu_Refresh( ); - return tmp_string = ""; -} - -// ---------------------------------------------------------------------------- -// HasKey -// ---------------------------------------------------------------------------- -static bool configuration_HasKey(std::string section, std::string name) { - char value[128]; - GetPrivateProfileString(section.c_str( ), name.c_str( ), "__TEST__", value, 128, configuration_filename.c_str( )); - std::string test = value; - if(test != "__TEST__") { - return true; - } - return false; -} - -// ---------------------------------------------------------------------------- -// WritePrivatePath -// ---------------------------------------------------------------------------- -static void configuration_WritePrivatePath(std::string section, std::string name, std::string path) { - WritePrivateProfileString(section.c_str( ), name.c_str( ), path.c_str( ), configuration_filename.c_str( )); -} - -// ---------------------------------------------------------------------------- -// WritePrivateBool -// ---------------------------------------------------------------------------- -static void configuration_WritePrivateBool(std::string section, std::string name, bool value) { - WritePrivateProfileString(section.c_str( ), name.c_str( ), common_Format(value).c_str( ), configuration_filename.c_str( )); -} - -// ---------------------------------------------------------------------------- -// WritePrivateUint -// ---------------------------------------------------------------------------- -static void configuration_WritePrivateUint(std::string section, std::string name, uint value) { - WritePrivateProfileString(section.c_str( ), name.c_str( ), common_Format(value).c_str( ), configuration_filename.c_str( )); -} - -// ---------------------------------------------------------------------------- -// ReadPrivatePath -// ---------------------------------------------------------------------------- -static std::string configuration_ReadPrivatePath(std::string section, std::string name, std::string defaultValue) { - char path[_MAX_PATH]; - GetPrivateProfileString(section.c_str( ), name.c_str( ), defaultValue.c_str( ), path, _MAX_PATH, configuration_filename.c_str( )); - return path; -} - -// ---------------------------------------------------------------------------- -// ReadPrivateBool -// ---------------------------------------------------------------------------- -static bool configuration_ReadPrivateBool(std::string section, std::string name, std::string defaultValue) { - char value[6]; - GetPrivateProfileString(section.c_str( ), name.c_str( ), defaultValue.c_str( ), value, 6, configuration_filename.c_str( )); - return common_ParseBool(value); -} - -// ---------------------------------------------------------------------------- -// ReadPrivateUint -// ---------------------------------------------------------------------------- -static uint configuration_ReadPrivateUint(std::string section, std::string name, uint value) { - return GetPrivateProfileInt(section.c_str( ), name.c_str( ), value, configuration_filename.c_str( )); -} - -// ---------------------------------------------------------------------------- -// Load -// ---------------------------------------------------------------------------- -std::string configuration_Load(std::string filename, std::string commandLine) { - configuration_filename = filename; - for(uint index = 0; index < 10; index++) { - console_recent[index] = configuration_ReadPrivatePath(CONFIGURATION_SECTION_RECENT, "Recent" + common_Format(index), ""); - } - - RECT windowRect = {0}; - windowRect.left = configuration_ReadPrivateUint(CONFIGURATION_SECTION_CONSOLE, "Window.Left", 0); - windowRect.top = configuration_ReadPrivateUint(CONFIGURATION_SECTION_CONSOLE, "Window.Top", 0); - windowRect.right = configuration_ReadPrivateUint(CONFIGURATION_SECTION_CONSOLE, "Window.Right", 0); - windowRect.bottom = configuration_ReadPrivateUint(CONFIGURATION_SECTION_CONSOLE, "Window.Bottom", 0); - console_SetWindowRect(windowRect); - - display_stretched = configuration_ReadPrivateBool(CONFIGURATION_SECTION_DISPLAY, "Stretched", "false"); -//Leonis - screenshot1 = configuration_ReadPrivateBool(CONFIGURATION_SECTION_DISPLAY, "Screenshot1", "false"); - screenshot2 = configuration_ReadPrivateBool(CONFIGURATION_SECTION_DISPLAY, "Screenshot2", "false"); - - display_mode.width = configuration_ReadPrivateUint(CONFIGURATION_SECTION_DISPLAY, "Mode.Width", 640); - display_mode.height = configuration_ReadPrivateUint(CONFIGURATION_SECTION_DISPLAY, "Mode.Height", 480); - display_mode.bpp = configuration_ReadPrivateUint(CONFIGURATION_SECTION_DISPLAY, "Mode.BPP", 8); - - if(configuration_HasKey(CONFIGURATION_SECTION_DISPLAY, "Palette.Default") && configuration_HasKey(CONFIGURATION_SECTION_DISPLAY, "Palette.Filename")) { - palette_default = configuration_ReadPrivateBool(CONFIGURATION_SECTION_DISPLAY, "Palette.Default", "true"); - if(!palette_default) { - palette_Load(configuration_ReadPrivatePath(CONFIGURATION_SECTION_DISPLAY, "Palette.Filename", "")); - } - } - - display_zoom = configuration_ReadPrivateUint(CONFIGURATION_SECTION_DISPLAY, "Zoom", 1); - if ( !strstr(commandLine.c_str(),"Fullscreen") && - !strstr(commandLine.c_str(),"fullscreen") ) - display_fullscreen = configuration_ReadPrivateBool(CONFIGURATION_SECTION_DISPLAY, "Fullscreen", "false"); - if ( !strstr(commandLine.c_str(),"MenuEnabled") && - !strstr(commandLine.c_str(),"menuenabled") ) - display_menuenabled = configuration_ReadPrivateBool(CONFIGURATION_SECTION_DISPLAY, "MenuEnabled", "true"); - - sound_SetMuted(configuration_ReadPrivateBool(CONFIGURATION_SECTION_SOUND, "Mute", "false")); - sound_latency = configuration_ReadPrivateUint(CONFIGURATION_SECTION_SOUND, "Latency", 1); - sound_SetSampleRate(configuration_ReadPrivateUint(CONFIGURATION_SECTION_SOUND, "Sample.Rate", 44100)); - samplerate=configuration_ReadPrivateUint(CONFIGURATION_SECTION_SOUND, "Sample.Rate", 44100); - - region_type = configuration_ReadPrivateUint(CONFIGURATION_SECTION_EMULATION, "Region", 2); - console_frameSkip = configuration_ReadPrivateUint(CONFIGURATION_SECTION_EMULATION, "Frame.Skip", 0); - - if(configuration_HasKey(CONFIGURATION_SECTION_EMULATION, "Bios.Enabled") && configuration_HasKey(CONFIGURATION_SECTION_EMULATION, "Bios.Filename")) { - bios_enabled = configuration_ReadPrivateBool(CONFIGURATION_SECTION_EMULATION, "Bios.Enabled", "false"); - if(bios_enabled) { - bios_Load(configuration_ReadPrivatePath(CONFIGURATION_SECTION_EMULATION, "Bios.Filename", "")); - } - } - - if(configuration_HasKey(CONFIGURATION_SECTION_EMULATION, "Database.Enabled") && configuration_HasKey(CONFIGURATION_SECTION_EMULATION, "Database.Filename")) { - database_enabled = configuration_ReadPrivateBool(CONFIGURATION_SECTION_EMULATION, "Database.Enabled", "true"); - if(database_enabled) { - database_filename = configuration_ReadPrivatePath(CONFIGURATION_SECTION_EMULATION, "Database.Filename", ""); - } - } - - for(index = 0; index < 17; index++) { - input_keys[index] = configuration_ReadPrivateUint(CONFIGURATION_SECTION_INPUT, "Key" + common_Format(index), input_keys[index]); - input_devices[index] = configuration_ReadPrivateUint(CONFIGURATION_SECTION_INPUT, "Device" + common_Format(index), input_devices[index]); - } - for(index = 0; index < 2; index++) { - user_keys[index] = configuration_ReadPrivateUint(CONFIGURATION_SECTION_INPUT, "User_Key" + common_Format(index), user_keys[index]); - user_devices[index] = configuration_ReadPrivateUint(CONFIGURATION_SECTION_INPUT, "User_Device" + common_Format(index), user_devices[index]); - user_modifiers[index] = configuration_ReadPrivateUint(CONFIGURATION_SECTION_INPUT, "User_Modifier" + common_Format(index), user_modifiers[index]); - } - - console_savePath = configuration_ReadPrivatePath(CONFIGURATION_SECTION_CONSOLE, "Save.Path", ""); - - return configuration_CommandLine(commandLine); -} - -// ---------------------------------------------------------------------------- -// Save -// ---------------------------------------------------------------------------- -void configuration_Save(std::string filename) { - configuration_filename = filename; - for(uint index = 0; index < 10; index++) { - configuration_WritePrivatePath(CONFIGURATION_SECTION_RECENT, "Recent" + common_Format(index), console_recent[index]); - } - - configuration_WritePrivateBool(CONFIGURATION_SECTION_DISPLAY, "Fullscreen", display_IsFullscreen( )); - configuration_WritePrivateBool(CONFIGURATION_SECTION_DISPLAY, "MenuEnabled", menu_IsEnabled( )); - configuration_WritePrivateUint(CONFIGURATION_SECTION_DISPLAY, "Mode.Height", display_mode.height); - configuration_WritePrivateUint(CONFIGURATION_SECTION_DISPLAY, "Mode.Width", display_mode.width); - configuration_WritePrivateUint(CONFIGURATION_SECTION_DISPLAY, "Mode.BPP", display_mode.bpp); - configuration_WritePrivateBool(CONFIGURATION_SECTION_DISPLAY, "Palette.Default", palette_default); - configuration_WritePrivatePath(CONFIGURATION_SECTION_DISPLAY, "Palette.Filename", palette_filename); - configuration_WritePrivateBool(CONFIGURATION_SECTION_DISPLAY, "Stretched", display_stretched); - -//Leonis - configuration_WritePrivateBool(CONFIGURATION_SECTION_DISPLAY, "Screenshot1", screenshot1); - configuration_WritePrivateBool(CONFIGURATION_SECTION_DISPLAY, "Screenshot2", screenshot2); - - configuration_WritePrivateUint(CONFIGURATION_SECTION_DISPLAY, "Zoom", display_zoom); - - configuration_WritePrivateBool(CONFIGURATION_SECTION_SOUND, "Mute", sound_IsMuted( )); - - configuration_WritePrivateUint(CONFIGURATION_SECTION_SOUND, "Sample.Rate", sound_GetSampleRate( )); - configuration_WritePrivateUint(CONFIGURATION_SECTION_SOUND, "Latency", sound_latency); - - configuration_WritePrivateUint(CONFIGURATION_SECTION_EMULATION, "Region", region_type); - configuration_WritePrivateUint(CONFIGURATION_SECTION_EMULATION, "Frame.Skip", console_frameSkip); - configuration_WritePrivatePath(CONFIGURATION_SECTION_EMULATION, "Bios.Filename", bios_filename); - configuration_WritePrivateBool(CONFIGURATION_SECTION_EMULATION, "Bios.Enabled", bios_enabled); - configuration_WritePrivatePath(CONFIGURATION_SECTION_EMULATION, "Database.Filename", database_filename); - configuration_WritePrivateBool(CONFIGURATION_SECTION_EMULATION, "Database.Enabled", database_enabled); - - for(index = 0; index < 17; index++) { - configuration_WritePrivateUint(CONFIGURATION_SECTION_INPUT, "Key" + common_Format(index), input_keys[index]); - configuration_WritePrivateUint(CONFIGURATION_SECTION_INPUT, "Device" + common_Format(index), input_devices[index]); - } - for(index = 0; index < 2; index++) { - configuration_WritePrivateUint(CONFIGURATION_SECTION_INPUT, "User_Key" + common_Format(index), user_keys[index]); - configuration_WritePrivateUint(CONFIGURATION_SECTION_INPUT, "User_Device" + common_Format(index), user_devices[index]); - configuration_WritePrivateUint(CONFIGURATION_SECTION_INPUT, "User_Modifier" + common_Format(index), user_modifiers[index]); - } - configuration_WritePrivatePath(CONFIGURATION_SECTION_CONSOLE, "Save.Path", console_savePath); - - RECT windowRect = console_GetWindowRect( ); - configuration_WritePrivateUint(CONFIGURATION_SECTION_CONSOLE, "Window.Left", windowRect.left); - configuration_WritePrivateUint(CONFIGURATION_SECTION_CONSOLE, "Window.Top", windowRect.top); - configuration_WritePrivateUint(CONFIGURATION_SECTION_CONSOLE, "Window.Right", windowRect.right); - configuration_WritePrivateUint(CONFIGURATION_SECTION_CONSOLE, "Window.Bottom", windowRect.bottom); -} diff --git a/Win/Configuration.h b/Win/Configuration.h deleted file mode 100755 index 461e5bc..0000000 --- a/Win/Configuration.h +++ /dev/null @@ -1,43 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Configuration.h -// ---------------------------------------------------------------------------- -#ifndef CONFIGURATION_H -#define CONFIGURATION_H - -#include -#include -#include "Console.h" - - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern std::string configuration_CommandLine(std::string commandLine); -extern std::string configuration_Load(std::string filename, std::string commandLine); -extern void configuration_Save(std::string filename); -extern bool configuration_enabled; -extern uint samplerate; - -#endif \ No newline at end of file diff --git a/Win/Console.cpp b/Win/Console.cpp deleted file mode 100755 index 502a7f6..0000000 --- a/Win/Console.cpp +++ /dev/null @@ -1,1063 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Console.cpp -// ---------------------------------------------------------------------------- -#include "Console.h" -#define WM_UNINITMENUPOPUP 0x125 - -std::string console_recent[10]; -std::string console_savePath; -std::string console_SSS; - -byte console_frameSkip = 0; -byte nf=0; - -static const DWORD CONSOLE_WINDOW_STYLE = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; -static const DWORD CONSOLE_WINDOW_STYLE_EX = WS_EX_CLIENTEDGE; -static HWND console_hWnd = NULL; -static HINSTANCE console_hInstance = NULL; -static bool console_suspended = false; -static bool console_rendering = false; -static RECT console_windowRect = {0}; - -// ---------------------------------------------------------------------------- -// SetSize -// ---------------------------------------------------------------------------- -static void console_SetSize(uint left, uint top, uint width, uint height) { - if(!display_IsFullscreen( )) { - GetWindowRect(console_hWnd, &console_windowRect); - RECT resizeRect = {left, top, width - 1, height - 1}; - AdjustWindowRectEx(&resizeRect, CONSOLE_WINDOW_STYLE, menu_IsEnabled( ), CONSOLE_WINDOW_STYLE_EX); - MoveWindow(console_hWnd, console_windowRect.left, console_windowRect.top, resizeRect.right - resizeRect.left, resizeRect.bottom - resizeRect.top, true); - } -} - -// ---------------------------------------------------------------------------- -// SetSuspended -// ---------------------------------------------------------------------------- -static void console_SetSuspended(bool suspended) { - console_suspended = suspended; - if(suspended) { - sound_Stop( ); - } - else if(prosystem_active && !prosystem_paused) { - sound_Play( ); - } -} - -// ---------------------------------------------------------------------------- -// SetCursorVisible -// ---------------------------------------------------------------------------- -static void console_SetCursorVisible(bool visible) { - if(visible) { - ShowCursor(true); - } - else { - while(ShowCursor(false) != -1) { - } - } -} - -// ---------------------------------------------------------------------------- -// Exit -// ---------------------------------------------------------------------------- -void console_Exit( ) { - configuration_Save(common_defaultPath + "ProSystem.ini"); - sound_Release( ); - display_Release( ); - input_Release( ); - DestroyWindow(console_hWnd); -} - -// ---------------------------------------------------------------------------- -// Close -// ---------------------------------------------------------------------------- -static void console_Close( ) { - prosystem_Close( ); - display_Clear( ); - sound_Stop( ); - sound_Clear( ); - SetWindowText(console_hWnd, CONSOLE_TITLE); -} - -// ---------------------------------------------------------------------------- -// Pause -// ---------------------------------------------------------------------------- -static void console_Pause(bool pause) { - prosystem_Pause(pause); - if(pause) { - sound_Stop( ); - } - else { - sound_Play( ); - } -} - -// ---------------------------------------------------------------------------- -// Reset -// ---------------------------------------------------------------------------- -static void console_Reset( ) { - sound_Stop( ); - prosystem_Reset( ); - sound_Play( ); -} - -// ---------------------------------------------------------------------------- -// SetRegion -// ---------------------------------------------------------------------------- -static void console_SetRegion(byte region) { - sound_Stop( ); - region_type = region; - region_Reset( ); - display_Clear( ); - display_ResetPalette( ); - console_SetZoom(display_zoom); - display_Show( ); - if(!prosystem_paused) { - sound_Play( ); - } -} - -// ---------------------------------------------------------------------------- -// SetMode -// ---------------------------------------------------------------------------- -static void console_SetMode(Mode mode) { - display_mode = mode; - if(display_IsFullscreen( )) { - console_SetFullscreen(true); - } -} - -// ---------------------------------------------------------------------------- -// AddRecent -// ---------------------------------------------------------------------------- -static void console_AddRecent(std::string filename) { - byte slot; - for(slot = 0; slot < 10; slot++) { - if(console_recent[slot] == filename) { - break; - } - } - if(slot != 10) { - for(byte index = 9; index > 0; index--) { - std::string temp = (slot > index - 1)? console_recent[index - 1]: console_recent[index]; - console_recent[index] = temp; - } - } - else { - for(byte index = 9; index > 0; index--) { - console_recent[index] = console_recent[index - 1]; - } - } - console_recent[0] = filename; -} - -// ---------------------------------------------------------------------------- -// Open -// ---------------------------------------------------------------------------- -static void console_Open( ) { - console_SetCursorVisible(true); - - int filterIndex = 2; - char path[_MAX_PATH] = {0}; - if(cartridge_IsLoaded( )) { - strcpy(path, cartridge_filename.c_str( )); - nf=1; - if(common_GetExtension(cartridge_filename) == ".zip") { - filterIndex = 3; - } - } - - OPENFILENAME openDialog = {0}; - openDialog.lStructSize = sizeof(OPENFILENAME); - openDialog.hwndOwner = console_hWnd; - openDialog.lpstrFilter = "All Files (*.*)\0*.*\0Atari Files (*.a78)\0*.a78\0Zip Files (*.zip)\0*.zip\0"; - openDialog.nFilterIndex = filterIndex; - openDialog.lpstrFile = path; - openDialog.nMaxFile = _MAX_PATH; - openDialog.nMaxFileTitle = _MAX_PATH; - openDialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - if(!cartridge_IsLoaded( )) { - openDialog.lpstrInitialDir = console_recent[0].c_str( ); - } - - if(GetOpenFileName(&openDialog)) { - console_Open(openDialog.lpstrFile); - console_SSS=openDialog.lpstrFile; - } - if(!menu_IsEnabled( ) && display_IsFullscreen( )) { - console_SetCursorVisible(false); - } -} - -// ---------------------------------------------------------------------------- -// Load -// ---------------------------------------------------------------------------- -static void console_Load( ) { - console_SetCursorVisible(true); - - char path[_MAX_PATH] = {0}; - OPENFILENAME loadDialog = {0}; - loadDialog.lStructSize = sizeof(OPENFILENAME); - loadDialog.hwndOwner = console_hWnd; - loadDialog.lpstrFilter = "All Files (*.*)\0*.*\0Save Files (*.sav)\0*.sav\0Zip Files (*.zip)\0*.zip\0"; - loadDialog.nFilterIndex = 2; - loadDialog.lpstrFile = path; - loadDialog.nMaxFile = _MAX_PATH; - loadDialog.nMaxFileTitle = _MAX_PATH; - loadDialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - loadDialog.lpstrInitialDir = console_savePath.c_str( ); - - if(GetOpenFileName(&loadDialog)) { - sound_Stop( ); - if(prosystem_Load(loadDialog.lpstrFile)) { - console_savePath = loadDialog.lpstrFile; - console_Pause(false); - } - sound_Play( ); - } - if(!menu_IsEnabled( ) && display_IsFullscreen( )) { - console_SetCursorVisible(false); - } -} - -// ---------------------------------------------------------------------------- -// Save -// ---------------------------------------------------------------------------- -static void console_Save( ) { - console_SetCursorVisible(true); - - char buffer[_MAX_PATH] = {0}; - OPENFILENAME saveDialog = {0}; - saveDialog.lStructSize = sizeof(OPENFILENAME); - saveDialog.hwndOwner = console_hWnd; - saveDialog.lpstrFilter = "All Files (*.*)\0*.*\0Save Files (*.sav)\0*.sav\0Zip Files (*.zip)\0*.zip\0"; - saveDialog.nFilterIndex = 2; - saveDialog.lpstrFile = buffer; - saveDialog.nMaxFile = _MAX_PATH; - saveDialog.nMaxFileTitle = _MAX_PATH; - saveDialog.lpstrDefExt = "sav"; - saveDialog.lpstrInitialDir = console_savePath.c_str( ); - - if(GetSaveFileName(&saveDialog)) { - if(!prosystem_Save(saveDialog.lpstrFile, (saveDialog.nFilterIndex == 3)? true: false)) { - logger_LogError(IDS_CONSOLE7,""); - } - else { - console_savePath = saveDialog.lpstrFile; - } - } - if(!menu_IsEnabled( ) && display_IsFullscreen( )) { - console_SetCursorVisible(false); - } -} - -// ---------------------------------------------------------------------------- -// SetMenuEnabled -// ---------------------------------------------------------------------------- -void console_SetMenuEnabled(bool enabled) { - sound_Stop( ); - menu_SetEnabled(enabled); - if(!enabled && display_IsFullscreen( )) { - console_SetCursorVisible(false); - } - else { - console_SetCursorVisible(true); - } - display_Clear( ); - console_SetZoom(display_zoom); - display_Show( ); - if(!prosystem_paused) { - sound_Play( ); - } -} - -// ---------------------------------------------------------------------------- -// SetUserInput -// ---------------------------------------------------------------------------- -void console_SetUserInput(byte *data, int index) { - - static byte user_data[2]; - - if ( user_data[index] != data[index] ) { - user_data[index] = data[index]; - if ( data[index] ) { - if ( index == 0 ) - console_SetMenuEnabled(!menu_IsEnabled( )); - else - console_Exit(); - } - } -} - -// ---------------------------------------------------------------------------- -// SetDisplayStretched -// ---------------------------------------------------------------------------- -static void console_SetDisplayStretched(bool stretched) { - display_Clear( ); - display_stretched = stretched; - display_Show( ); -} - -// ---------------------------------------------------------------------------- -// OpenPaletteHook -// ---------------------------------------------------------------------------- -static UINT CALLBACK console_OpenPaletteHook(HWND childDialog, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) { - case WM_INITDIALOG: - SendMessage(GetParent(childDialog), CDM_SETCONTROLTEXT, 1038, (LONG)&"Default"); - break; - case WM_NOTIFY: - OFNOTIFY* notify = (OFNOTIFY*)lParam; - if(notify->hdr.code == CDN_HELP) { - notify->lpOFN->lCustData = true; - PostMessage(GetParent(childDialog), WM_COMMAND, IDCANCEL, 0); - } - break; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// OpenPalette -// ---------------------------------------------------------------------------- -static void console_OpenPalette( ) { - console_SetCursorVisible(true); - - char path[_MAX_PATH] = {0}; - strcpy(path, palette_filename.c_str( )); - - OPENFILENAME openDialog = {0}; - openDialog.lStructSize = sizeof(OPENFILENAME); - openDialog.hwndOwner = console_hWnd; - openDialog.lpstrFilter = "All Files (*.*)\0*.*\0Palette Files (*.pal)\0*.pal\0"; - openDialog.nFilterIndex = 2; - openDialog.lpstrFile = path; - openDialog.nMaxFile = _MAX_PATH; - openDialog.nMaxFileTitle = _MAX_PATH; - openDialog.Flags = OFN_EXPLORER | OFN_ENABLEHOOK | OFN_SHOWHELP; - openDialog.lpstrTitle = "Palette"; - openDialog.lCustData = false; - openDialog.lpfnHook = console_OpenPaletteHook; - - if(GetOpenFileName(&openDialog) || openDialog.lCustData) { - if(openDialog.lCustData) { - palette_default = true; - region_Reset( ); - display_ResetPalette( ); - } - else { - palette_default = false; - palette_Load(openDialog.lpstrFile); - } - display_Clear( ); - display_ResetPalette( ); - display_Show( ); - } - if(!menu_IsEnabled( ) && display_IsFullscreen( )) { - console_SetCursorVisible(false); - } -} - -// ---------------------------------------------------------------------------- -// SaveScreenshot -// ---------------------------------------------------------------------------- -static void console_SaveScreenshot( ) { - console_SetCursorVisible(true); - - - char buf[270]; - char bbf[20]; -std::string console_S; - int position = console_SSS.rfind('.'); - if(position != -1) { - console_S=console_SSS.substr(0, position); - } - if (screenshot1) - { - console_S=common_Remove(console_S,'!'); - console_S=common_Remove(console_S,'['); - console_S=common_Remove(console_S,']'); - console_S=common_Remove(console_S,'('); - console_S=common_Remove(console_S,')'); - console_S=common_Remove(console_S,','); - } - if (screenshot2) - { - console_S=common_Replace(console_S, ' ','_'); - } - - - strcpy(buf,console_S.c_str()); - sprintf(bbf, "%.2d", nf); - nf++; - strcat(buf,"_"); - strcat(buf,bbf); - strcat(buf,".bmp"); - - - if(!display_TakeScreenshot(buf)) { - logger_LogError(IDS_CONSOLE1,""); - } - if(!menu_IsEnabled( ) && display_IsFullscreen( )) { - console_SetCursorVisible(false); - } -} - -// ---------------------------------------------------------------------------- -// SaveScreenshot1 -// ---------------------------------------------------------------------------- -static void console_SaveScreenshot1( ) { - screenshot1=! screenshot1; - -} - -// ---------------------------------------------------------------------------- -// SaveScreenshot2 -// ---------------------------------------------------------------------------- -static void console_SaveScreenshot2( ) { - screenshot2=! screenshot2; -} - -// ---------------------------------------------------------------------------- -// OpenBiosHook -// ---------------------------------------------------------------------------- -static UINT CALLBACK console_OpenHook(HWND childDialog, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) { - case WM_INITDIALOG: - SendMessage(GetParent(childDialog), CDM_SETCONTROLTEXT, 1038, (LONG)&"Disable"); - SendMessage(GetParent(childDialog), CDM_SETCONTROLTEXT, 1, (LONG)&"Enable"); - break; - case WM_NOTIFY: - OFNOTIFY* notify = (OFNOTIFY*)lParam; - if(notify->hdr.code == CDN_HELP) { - notify->lpOFN->lCustData = true; - PostMessage(GetParent(childDialog), WM_COMMAND, IDCANCEL, 0); - } - break; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// OpenBios -// ---------------------------------------------------------------------------- -static void console_OpenBios( ) { - console_SetCursorVisible(true); - - char path[_MAX_PATH] = {0}; - strcpy(path, bios_filename.c_str( )); - - int filterIndex = 2; - if(common_GetExtension(bios_filename) == ".zip") { - filterIndex = 3; - } - - OPENFILENAME biosDialog = {0}; - biosDialog.lStructSize = sizeof(OPENFILENAME); - biosDialog.hwndOwner = console_hWnd; - biosDialog.lpstrFilter = "All Files (*.*)\0*.*\0Bios Files (*.rom)\0*.rom\0Zip Files (*.zip)\0*.zip\0"; - biosDialog.nFilterIndex = filterIndex; - biosDialog.lpstrFile = path; - biosDialog.nMaxFile = _MAX_PATH; - biosDialog.nMaxFileTitle = _MAX_PATH; - biosDialog.Flags = OFN_EXPLORER | OFN_ENABLEHOOK | OFN_SHOWHELP; - biosDialog.lpstrTitle = "Bios"; - biosDialog.lCustData = false; - biosDialog.lpfnHook = console_OpenHook; - - if(GetOpenFileName(&biosDialog) || biosDialog.lCustData) { - if(biosDialog.lCustData) { - bios_enabled = false; - } - else { - bios_Load(biosDialog.lpstrFile); - bios_enabled = true; - } - } - if(!menu_IsEnabled( ) && display_IsFullscreen( )) { - console_SetCursorVisible(false); - } -} - -// ---------------------------------------------------------------------------- -// SetSampleRate -// ---------------------------------------------------------------------------- -static void console_SetSampleRate(uint sampleRate) { - sound_Stop( ); - sound_SetSampleRate(sampleRate); - menu_Refresh( ); - if(!prosystem_paused) { - sound_Play( ); - } -} - -// ---------------------------------------------------------------------------- -// SetLatency -// ---------------------------------------------------------------------------- -static void console_SetLatency(byte latency) { - sound_Stop( ); - sound_latency = latency; - if(!prosystem_paused) { - sound_Play( ); - } -} - -// ---------------------------------------------------------------------------- -// SetMuted -// ---------------------------------------------------------------------------- -static void console_SetMuted(bool muted) { - sound_Stop( ); - sound_SetMuted(muted); - if(!prosystem_paused) { - sound_Play( ); - } -} - -// ---------------------------------------------------------------------------- -// SetFrameSkip -// ---------------------------------------------------------------------------- -static void console_SetFrameSkip(byte frameSkip) { - sound_Stop( ); - console_frameSkip = frameSkip; - if(prosystem_active && !prosystem_paused) { - sound_Play( ); - } -} - -// ---------------------------------------------------------------------------- -// OpenDatabase -// ---------------------------------------------------------------------------- -static void console_OpenDatabase( ) { - console_SetCursorVisible(true); - - char path[_MAX_PATH] = {0}; - strcpy(path, database_filename.c_str( )); - - OPENFILENAME databaseDialog = {0}; - databaseDialog.lStructSize = sizeof(OPENFILENAME); - databaseDialog.hwndOwner = console_hWnd; - databaseDialog.lpstrFilter = "All Files (*.*)\0*.*\0Database Files (*.dat)\0*.dat\0"; - databaseDialog.nFilterIndex = 2; - databaseDialog.lpstrFile = path; - databaseDialog.nMaxFile = _MAX_PATH; - databaseDialog.nMaxFileTitle = _MAX_PATH; - databaseDialog.Flags = OFN_EXPLORER | OFN_ENABLEHOOK | OFN_SHOWHELP; - databaseDialog.lpstrTitle = "Database"; - databaseDialog.lCustData = false; - databaseDialog.lpfnHook = console_OpenHook; - - if(GetOpenFileName(&databaseDialog) || databaseDialog.lCustData) { - if(databaseDialog.lCustData) { - database_enabled = false; - } - else { - database_filename = databaseDialog.lpstrFile; - database_enabled = true; - } - } - if(!menu_IsEnabled( ) && display_IsFullscreen( )) { - console_SetCursorVisible(false); - } -} - -// ---------------------------------------------------------------------------- -// Procedure -// ---------------------------------------------------------------------------- -static LRESULT CALLBACK console_Procedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) { - case WM_DESTROY: - PostQuitMessage(0); - break; - case WM_CLOSE: - console_Exit( ); - break; - case WM_INITMENU: - menu_Refresh( ); - break; - case WM_UNINITMENUPOPUP: - display_Show( ); - break; - case WM_ENTERMENULOOP: - console_SetSuspended(true); - break; - case WM_EXITMENULOOP: - console_SetSuspended(false); - break; - case WM_COMMAND: - switch((word)wParam) { - case IDM_FILE_OPEN: - console_Open( ); - break; - case IDM_FILE_CLOSE: - console_Close( ); - break; - case IDM_RECENT_SLOT0: - console_Open(console_recent[0]); - break; - case IDM_RECENT_SLOT1: - console_Open(console_recent[1]); - break; - case IDM_RECENT_SLOT2: - console_Open(console_recent[2]); - break; - case IDM_RECENT_SLOT3: - console_Open(console_recent[3]); - break; - case IDM_RECENT_SLOT4: - console_Open(console_recent[4]); - break; - case IDM_RECENT_SLOT5: - console_Open(console_recent[5]); - break; - case IDM_RECENT_SLOT6: - console_Open(console_recent[6]); - break; - case IDM_RECENT_SLOT7: - console_Open(console_recent[7]); - break; - case IDM_RECENT_SLOT8: - console_Open(console_recent[8]); - break; - case IDM_RECENT_SLOT9: - console_Open(console_recent[9]); - break; - case IDM_FILE_SAVE: - console_Save( ); - break; - case IDM_FILE_LOAD: - console_Load( ); - break; - case IDM_FILE_EXIT: - console_Exit( ); - break; - case IDM_OPTIONS_RESET: - console_Reset( ); - break; - case IDM_OPTIONS_PAUSE: - console_Pause(!prosystem_paused); - break; - case IDM_DISPLAY_FULLSCREEN: - console_SetFullscreen(!display_IsFullscreen( )); - break; - case IDM_DISPLAY_STRETCHED: - console_SetDisplayStretched(!display_stretched); - break; - case IDM_DISPLAY_PALETTE: - console_OpenPalette( ); - break; - case IDM_DISPLAY_ZOOM1: - console_SetZoom(1); - break; - case IDM_DISPLAY_ZOOM2: - console_SetZoom(2); - break; - case IDM_DISPLAY_ZOOM3: - console_SetZoom(3); - break; - case IDM_DISPLAY_ZOOM4: - console_SetZoom(4); - break; - case IDM_DISPLAY_SCREENSHOT: - console_SaveScreenshot( ); - break; - -//Leonis - case ID_OPTIONS_DISPLAY_SCREENSHOT_REMOVENONWEBSYMBOLS: - console_SaveScreenshot1( ); - break; - case ID_OPTIONS_DISPLAY_SCREENSHOT_REPLACESPACESBY: - console_SaveScreenshot2( ); - break; - - case IDM_SOUND_MUTE: - console_SetMuted(!sound_IsMuted( )); - break; - case IDM_SAMPLERATE_11025: - console_SetSampleRate(11025); - break; - case IDM_SAMPLERATE_22050: - console_SetSampleRate(22050); - break; - case IDM_SAMPLERATE_31440: - console_SetSampleRate(31440); - break; - case IDM_SAMPLERATE_44100: - console_SetSampleRate(44100); - break; - case IDM_SAMPLERATE_48000: - console_SetSampleRate(48000); - break; - case IDM_SAMPLERATE_96000: - console_SetSampleRate(96000); - break; - case IDM_LATENCY_NONE: - console_SetLatency(SOUND_LATENCY_NONE); - break; - case IDM_LATENCY_VERYLOW: - console_SetLatency(SOUND_LATENCY_VERY_LOW); - break; - case IDM_LATENCY_LOW: - console_SetLatency(SOUND_LATENCY_LOW); - break; - case IDM_LATENCY_MEDIUM: - console_SetLatency(SOUND_LATENCY_MEDIUM); - break; - case IDM_LATENCY_HIGH: - console_SetLatency(SOUND_LATENCY_HIGH); - break; - case IDM_LATENCY_VERYHIGH: - console_SetLatency(SOUND_LATENCY_VERY_HIGH); - break; - case IDM_OPTIONS_MENU: - console_SetMenuEnabled(!menu_IsEnabled( )); - break; - case IDM_REGION_AUTO: - console_SetRegion(REGION_AUTO); - break; - case IDM_REGION_NTSC: - console_SetRegion(REGION_NTSC); - break; - case IDM_REGION_PAL: - console_SetRegion(REGION_PAL); - break; - case IDM_FRAMESKIP_0: - console_SetFrameSkip(0); - break; - case IDM_FRAMESKIP_1: - console_SetFrameSkip(1); - break; - case IDM_FRAMESKIP_2: - console_SetFrameSkip(2); - break; - case IDM_FRAMESKIP_3: - console_SetFrameSkip(3); - break; - case IDM_FRAMESKIP_4: - console_SetFrameSkip(4); - break; - case IDM_FRAMESKIP_5: - console_SetFrameSkip(5); - break; - case IDM_FRAMESKIP_6: - console_SetFrameSkip(6); - break; - case IDM_FRAMESKIP_7: - console_SetFrameSkip(7); - break; - case IDM_FRAMESKIP_8: - console_SetFrameSkip(8); - break; - case IDM_FRAMESKIP_9: - console_SetFrameSkip(9); - break; - case IDM_FRAMESKIP_10: - console_SetFrameSkip(10); - break; - case IDM_FRAMESKIP_15: - console_SetFrameSkip(15); - break; - case IDM_FRAMESKIP_20: - console_SetFrameSkip(20); - break; - case IDM_FRAMESKIP_25: - console_SetFrameSkip(25); - break; - case IDM_FRAMESKIP_30: - console_SetFrameSkip(30); - break; - case IDM_EMULATION_BIOS: - console_OpenBios( ); - break; - case IDM_EMULATION_DATABASE: - console_OpenDatabase( ); - break; - case IDM_INPUT_CONTROLLER1: - input_ShowController1Dialog(console_hWnd, console_hInstance); - break; - case IDM_INPUT_CONTROLLER2: - input_ShowController2Dialog(console_hWnd, console_hInstance); - break; - case IDM_INPUT_CONSOLE: - input_ShowConsoleDialog(console_hWnd, console_hInstance); - break; - case IDM_INPUT_USER: - input_ShowUserDialog(console_hWnd, console_hInstance); - break; - case IDM_HELP_CONTENTS: - help_ShowContents( ); - break; - case IDM_HELP_ABOUT: - about_Show(console_hWnd, console_hInstance); - break; - default: - if((word)wParam >= IDM_MODES_BASE && (word)wParam < IDM_MODES_LAST) { - int index = ((word)wParam) - IDM_MODES_BASE; - if(index < display_modes.size( )) { - console_SetMode(display_modes[index]); - } - } - break; - } - break; - case WM_ACTIVATE: - console_SetSuspended(((word)(wParam) == WA_INACTIVE)? true: false); - break; - case WM_ENTERSIZEMOVE: - console_SetSuspended(true); - break; - case WM_EXITSIZEMOVE: - console_SetSuspended(false); - break; - case WM_ERASEBKGND: - DefWindowProc(hWnd, message, wParam, lParam); - if(!console_suspended) { - display_Show( ); - } - return 1; - case WM_PAINT: - if(prosystem_paused || console_suspended) { - display_Show( ); - } - else { - return DefWindowProc(hWnd, message, wParam, lParam); - } - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - timer_Reset( ); - return 0; -} - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -bool console_Initialize(HINSTANCE hInstance, std::string commandLine) { - std::string romfile; - WNDCLASSEX wClass = {0}; - wClass.cbSize = sizeof(WNDCLASSEX); - wClass.style = 0; - wClass.lpfnWndProc = console_Procedure; - wClass.cbClsExtra = 0; - wClass.cbWndExtra = 0; - wClass.hInstance = hInstance; - wClass.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON_PROSYSTEM), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); - wClass.hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON_PROSYSTEM), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);; - wClass.hCursor = LoadCursor(NULL, IDC_ARROW); - wClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); - wClass.lpszMenuName = NULL; - wClass.lpszClassName = CONSOLE_TITLE; - - if(!RegisterClassEx(&wClass)) { - logger_LogError(IDS_CONSOLE2,""); - logger_LogError(common_GetErrorMessage( ), ""); - return false; - } - - database_Initialize( ); - timer_Initialize( ); - console_hInstance = hInstance; - romfile = configuration_Load(common_defaultPath + "ProSystem.ini", commandLine); - - // Setup Display for Fullscreen or Windowed - if ( display_fullscreen ) { - console_hWnd = CreateWindowEx(WS_EX_TOPMOST, CONSOLE_TITLE, CONSOLE_TITLE, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); - if(!menu_Initialize(console_hWnd, hInstance)) { - logger_LogError(IDS_CONSOLE3,""); - return false; - } - menu_SetEnabled(display_menuenabled); - if(!display_menuenabled) { - console_SetCursorVisible(false); - } - if(!display_Initialize(console_hWnd)) { - logger_LogError(IDS_CONSOLE4,""); - return false; - } - SetWindowPos(console_hWnd, NULL, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOMOVE); - console_SetSize(0, 0, maria_visibleArea.GetLength( ) * display_zoom, maria_visibleArea.GetHeight( ) * display_zoom); - if(!display_SetFullscreen( )) { - logger_LogError(IDS_CONSOLE5,""); - return false; - } - } - else { - console_hWnd = CreateWindowEx(CONSOLE_WINDOW_STYLE_EX, CONSOLE_TITLE, CONSOLE_TITLE, CONSOLE_WINDOW_STYLE, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); - if(!menu_Initialize(console_hWnd, hInstance)) { - logger_LogError(IDS_CONSOLE3,""); - return false; - } - menu_SetEnabled(display_menuenabled); - if(!display_Initialize(console_hWnd)) { - logger_LogError(IDS_CONSOLE4,""); - return false; - } - SetWindowPos(console_hWnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); - console_SetSize(0, 0, maria_visibleArea.GetLength( ) * display_zoom, maria_visibleArea.GetHeight( ) * display_zoom); - if(!display_SetWindowed( )) { - logger_LogError(IDS_CONSOLE5,""); - return false; - } - - } - if(!sound_Initialize(console_hWnd)) { - logger_LogError(IDS_CONSOLE6,""); - return false; - } - help_Initialize(console_hWnd); - if(!input_Initialize(console_hWnd, hInstance)) { - logger_LogError(IDS_CONSOLE6,""); - return false; - } - - ShowWindow(console_hWnd, SW_SHOW); - display_Clear( ); - display_Show( ); - if ( !romfile.empty() ) - console_Open(common_Remove(romfile, '"')); - else { - console_SetMenuEnabled(true); - } - return true; -} - -// ---------------------------------------------------------------------------- -// Run -// ---------------------------------------------------------------------------- -void console_Run( ) { - MSG message; - while(true) { - if(PeekMessage(&message, NULL, 0, 0, PM_NOREMOVE( ))) { - if(GetMessage(&message, NULL, 0, 0)) { - if(!TranslateAccelerator(console_hWnd, menu_hAccel, &message)) { - TranslateMessage(&message); - DispatchMessage(&message); - } - } - else { - return; - } - } - byte data[19]; - input_GetKeyboardState(data); - if(prosystem_active && !prosystem_paused && !console_suspended) { - if(!console_rendering) { - prosystem_ExecuteFrame(data); - console_rendering = true; - } - else if(timer_IsTime( )) { - if(console_frameSkip == 0 || (prosystem_frame % (prosystem_frequency / console_frameSkip) != 0)) { - display_Show( ); - } - sound_Store( ); - console_rendering = false; - } - } - } -} - -// ---------------------------------------------------------------------------- -// Open -// ---------------------------------------------------------------------------- -void console_Open(std::string filename) { - if(cartridge_Load(filename)) { - sound_Stop( ); - display_Clear( ); - database_Load(cartridge_digest); - prosystem_Reset( ); - std::string title = std::string(CONSOLE_TITLE) + " - " + common_Trim(cartridge_title); - SetWindowText(console_hWnd, title.c_str( )); - console_AddRecent(filename); - display_ResetPalette( ); - console_SetZoom(display_zoom); - sound_Play( ); - } -} - -// ---------------------------------------------------------------------------- -// SetZoom -// ---------------------------------------------------------------------------- -void console_SetZoom(byte zoom) { - if(zoom >= 1 && zoom <= 4) { - console_SetSize(0, 0, maria_visibleArea.GetLength( ) * zoom, maria_visibleArea.GetHeight( ) * zoom); - display_zoom = zoom; - display_Clear( ); - display_Show( ); - } -} - -// ---------------------------------------------------------------------------- -// SetFullscreen -// ---------------------------------------------------------------------------- -void console_SetFullscreen(bool fullscreen) { - if(fullscreen) { - console_SetSuspended(true); - GetWindowRect(console_hWnd, &console_windowRect); - console_windowRect.left = 0; - console_windowRect.right = 0; - console_windowRect.bottom = display_mode.height; - console_windowRect.right = display_mode.width; - console_SetWindowRect(console_windowRect); - display_SetFullscreen( ); - //SetWindowRect(console_hWnd, &console_windowRect); - SetWindowLong(console_hWnd, GWL_EXSTYLE, WS_EX_TOPMOST); - SetWindowLong(console_hWnd, GWL_STYLE, WS_POPUP); - SetWindowPos(console_hWnd, NULL, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOMOVE); - //SetWindowPos(console_hWnd, NULL, 0, 0, display_mode.width, display_mode.height, SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOMOVE); - display_Clear( ); - if(!menu_IsEnabled( )) { - console_SetCursorVisible(false); - } - console_SetZoom(display_zoom); - display_Show( ); - console_SetSuspended(false); - } - else { - console_SetSuspended(true); - display_SetWindowed( ); - MoveWindow(console_hWnd, console_windowRect.left, console_windowRect.top, console_windowRect.right - console_windowRect.left, console_windowRect.bottom - console_windowRect.top, TRUE); - SetWindowLong(console_hWnd, GWL_STYLE, CONSOLE_WINDOW_STYLE); - SetWindowLong(console_hWnd, GWL_EXSTYLE, CONSOLE_WINDOW_STYLE_EX); - SetWindowPos(console_hWnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE); - console_SetCursorVisible(true); - console_SetZoom(display_zoom); - display_Show( ); - console_SetSuspended(false); - } -} - -// ---------------------------------------------------------------------------- -// GetWindowRect -// ---------------------------------------------------------------------------- -RECT console_GetWindowRect( ) { - GetWindowRect(console_hWnd, &console_windowRect); - return console_windowRect; -} - -// ---------------------------------------------------------------------------- -// SetWindowRect -// ---------------------------------------------------------------------------- -void console_SetWindowRect(RECT windowRect) { - console_windowRect = windowRect; - MoveWindow(console_hWnd, console_windowRect.left, console_windowRect.top, console_windowRect.right - console_windowRect.left, console_windowRect.bottom - console_windowRect.top, true); -} diff --git a/Win/Console.h b/Win/Console.h deleted file mode 100755 index 877f93b..0000000 --- a/Win/Console.h +++ /dev/null @@ -1,63 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Console.h -// ---------------------------------------------------------------------------- -#ifndef CONSOLE_H -#define CONSOLE_H -#define CONSOLE_VERSION 1.3 -#define CONSOLE_TITLE "ProSystem Emulator" -#define NULL 0 - -#include -#include -#include "Resource.h" -#include "Menu.h" -#include "Configuration.h" -#include "Display.h" -#include "Input.h" -#include "Database.h" -#include "Sound.h" -#include "Timer.h" -#include "ProSystem.h" -#include "Help.h" -#include "About.h" - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern bool console_Initialize(HINSTANCE hInstance, std::string commandLine); -extern void console_Run( ); -extern void console_Open(std::string filename); -extern void console_SetZoom(byte zoom); -extern void console_SetFullscreen(bool fullscreen); -extern RECT console_GetWindowRect( ); -extern void console_SetWindowRect(RECT windowRect); -extern void console_SetMenuEnabled(bool enabled); -extern void console_SetUserInput(byte *data, int index); -extern void console_Exit(void); -extern std::string console_recent[10]; -extern std::string console_savePath; -extern byte console_frameSkip; - -#endif diff --git a/Win/Database.cpp b/Win/Database.cpp deleted file mode 100755 index 7c1b7bb..0000000 --- a/Win/Database.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Database.cpp -// ---------------------------------------------------------------------------- -#include "Database.h" - -bool database_enabled = true; -std::string database_filename; - -static std::string database_GetValue(std::string entry) { - int index = entry.rfind('='); - return entry.substr(index + 1); -} - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -void database_Initialize( ) { - database_filename = common_defaultPath + "ProSystem.dat"; -} - -// ---------------------------------------------------------------------------- -// Load -// ---------------------------------------------------------------------------- -bool database_Load(std::string digest) { - if(database_enabled) { - logger_LogInfo(IDS_DATABASE1, database_filename); - - FILE* file = fopen(database_filename.c_str( ), "r"); - if(file == NULL) { - logger_LogError(IDS_DATABASE2,""); - return false; - } - - char buffer[256]; - while(fgets(buffer, 256, file) != NULL) { - std::string line = buffer; - if(line.compare(1, 32, digest.c_str( )) == 0) { - std::string entry[7]; - for(int index = 0; index < 7; index++) { - fgets(buffer, 256, file); - entry[index] = common_Remove(buffer, '\n'); - } - - cartridge_title = database_GetValue(entry[0]); - cartridge_type = common_ParseByte(database_GetValue(entry[1])); - cartridge_pokey = common_ParseBool(database_GetValue(entry[2])); - cartridge_controller[0] = common_ParseByte(database_GetValue(entry[3])); - cartridge_controller[1] = common_ParseByte(database_GetValue(entry[4])); - cartridge_region = common_ParseByte(database_GetValue(entry[5])); - cartridge_flags = common_ParseUint(database_GetValue(entry[6])); - break; - } - } - - fclose(file); - } - return true; -} - - diff --git a/Win/Database.h b/Win/Database.h deleted file mode 100755 index 49432ae..0000000 --- a/Win/Database.h +++ /dev/null @@ -1,43 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Database.h -// ---------------------------------------------------------------------------- -#ifndef DATABASE_H -#define DATABASE_H - -#include -#include -#include "Cartridge.h" -#include "Logger.h" -#include "Common.h" - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern void database_Initialize( ); -extern bool database_Load(std::string digest); -extern bool database_enabled; -extern std::string database_filename; - -#endif \ No newline at end of file diff --git a/Win/Display.cpp b/Win/Display.cpp deleted file mode 100755 index a9f5e29..0000000 --- a/Win/Display.cpp +++ /dev/null @@ -1,745 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2003, 2004 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Display.cpp -// ---------------------------------------------------------------------------- -#include "Display.h" -#define DISPLAY_LENGTH 320 -#define DISPLAY_HEIGHT 292 - -bool display_stretched = false; -bool display_menuenabled = true; -byte display_zoom = 1; -bool display_fullscreen = false; -std::vector display_modes; -Mode display_mode = {640, 480, 8, 0, 0, 0}; - -static LPDIRECTDRAW display_ddraw = NULL; -static LPDIRECTDRAWSURFACE display_primary = NULL; -static LPDIRECTDRAWSURFACE display_offscreen = NULL; -static LPDIRECTDRAWPALETTE display_palette = NULL; -static LPDIRECTDRAWCLIPPER display_clipper = NULL; -static HWND display_hWnd = NULL; -static word display_palette16[256] = {0}; -static byte display_palette24[768] = {0}; -static uint display_palette32[256] = {0}; - -// ---------------------------------------------------------------------------- -// ToMode -// ---------------------------------------------------------------------------- -static Mode display_ToMode(LPDDSURFACEDESC surfaceDesc) { - Mode mode = {0}; - if(surfaceDesc != NULL) { - mode.width = surfaceDesc->dwWidth; - mode.height = surfaceDesc->dwHeight; - mode.bpp = surfaceDesc->ddpfPixelFormat.dwRGBBitCount; - mode.rmask = surfaceDesc->ddpfPixelFormat.dwRBitMask; - mode.gmask = surfaceDesc->ddpfPixelFormat.dwGBitMask; - mode.bmask = surfaceDesc->ddpfPixelFormat.dwBBitMask; - } - return mode; -} - -// ---------------------------------------------------------------------------- -// EnumerateModes -// ---------------------------------------------------------------------------- -static HRESULT WINAPI display_EnumerateModes(LPDDSURFACEDESC surfaceDesc, LPVOID context) { - Mode mode = display_ToMode(surfaceDesc); - if(mode.width != 0 && mode.height != 0 && mode.bpp != 0) { - display_modes.push_back(mode); - } - return DDENUMRET_OK; -} - -// ---------------------------------------------------------------------------- -// SetClipper -// ---------------------------------------------------------------------------- -static bool display_SetClipper( ) { - HRESULT hr = display_ddraw->CreateClipper(0, &display_clipper, NULL); - if(FAILED(hr) || display_clipper == NULL) { - logger_LogError(IDS_DISPLAY1,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = display_clipper->SetHWnd(0, display_hWnd); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY2, ""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = display_primary->SetClipper(display_clipper); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY3,""); - logger_LogError("",common_Format(hr)); - return false; - } - return true; -} - -// ---------------------------------------------------------------------------- -// GetColorBits -// ---------------------------------------------------------------------------- -static void display_GetColorBits(uint bitMask, uint* shift, uint* bits) { - *shift = 0; - if(bitMask) { - while((bitMask & 1) == 0) { - (*shift)++; - bitMask >>= 1; - } - } - *bits = 0; - while((bitMask & 1) != 0) { - (*bits)++; - bitMask >>= 1; - } -} - -// ---------------------------------------------------------------------------- -// GetStretchedRect -// ---------------------------------------------------------------------------- -static RECT display_GetStretchedRect( ) { - RECT clientRect; - GetClientRect(display_hWnd, &clientRect); - - POINT point = {clientRect.left, clientRect.top}; - ClientToScreen(display_hWnd, &point); - - RECT targetRect = {0}; - targetRect.left = point.x; - targetRect.top = point.y; - targetRect.right = targetRect.left + clientRect.right; - targetRect.bottom = targetRect.top + clientRect.bottom; - return targetRect; -} - -// ---------------------------------------------------------------------------- -// GetCenteredRect -// ---------------------------------------------------------------------------- -static RECT display_GetCenteredRect( ) { - RECT clientRect; - GetClientRect(display_hWnd, &clientRect); - - POINT center = {(clientRect.right + 1) / 2, (clientRect.bottom + 1) / 2}; - POINT corner = {center.x - ((maria_visibleArea.GetLength( ) * display_zoom) / 2), center.y - ((maria_visibleArea.GetHeight( ) * display_zoom) / 2)}; - ClientToScreen(display_hWnd, &corner); - - RECT targetRect; - targetRect.left = corner.x; - targetRect.top = corner.y; - targetRect.right = targetRect.left + (maria_visibleArea.GetLength( ) * display_zoom); - targetRect.bottom = targetRect.top + (maria_visibleArea.GetHeight( ) * display_zoom); - return targetRect; -} - -// ---------------------------------------------------------------------------- -// RestorePrimary -// ---------------------------------------------------------------------------- -static bool display_RestorePrimary( ) { - HRESULT hr = display_primary->Restore( ); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY4,""); - logger_LogError("",common_Format(hr)); - return false; - } - return true; -} - -// ---------------------------------------------------------------------------- -// RestoreOffscreen -// ---------------------------------------------------------------------------- -static bool display_RestoreOffscreen( ) { - HRESULT hr = display_offscreen->Restore( ); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY5,""); - logger_LogError("",common_Format(hr)); - return false; - } - return true; -} - -// ---------------------------------------------------------------------------- -// ResetPalette08 -// ---------------------------------------------------------------------------- -static bool display_ResetPalette08( ) { - if(display_ddraw == NULL) { - logger_LogError(IDS_DISPLAY6,""); - return false; - } - if(display_primary == NULL) { - logger_LogError(IDS_DISPLAY7,""); - return false; - } - if(display_offscreen == NULL) { - logger_LogError(IDS_DISPLAY8,""); - return false; - } - if(display_palette == NULL) { - logger_LogError(IDS_DISPLAY9,""); - return false; - } - - PALETTEENTRY paletteEntry[256]; - for(int index = 0; index < 256; index++) { - PALETTEENTRY entry; - entry.peRed = palette_data[(index * 3) + 0]; - entry.peGreen = palette_data[(index * 3) + 1]; - entry.peBlue = palette_data[(index * 3) + 2]; - entry.peFlags = 0; - paletteEntry[index] = entry; - } - - HRESULT hr = display_palette->SetEntries(0, 0, 256, paletteEntry); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY10,""); - logger_LogError("",common_Format(hr)); - return false; - } - return true; -} - -// ---------------------------------------------------------------------------- -// ResetPalette16 -// ---------------------------------------------------------------------------- -static bool display_ResetPalette16( ) { - if(display_ddraw == NULL) { - logger_LogError(IDS_DISPLAY6,""); - return false; - } - - DDSURFACEDESC surfaceDesc = {0}; - surfaceDesc.dwSize = sizeof(DDSURFACEDESC); - HRESULT hr = display_ddraw->GetDisplayMode(&surfaceDesc); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY11,""); - logger_LogError("",common_Format(hr)); - return false; - } - - Mode mode16 = display_ToMode(&surfaceDesc); - if(mode16.bpp != 16) { - for(int index = 0; index < display_modes.size( ); index++) { - Mode mode = display_modes[index]; - if(mode.bpp == 16) { - mode16 = mode; - break; - } - } - } - - uint rshift, rsize; - uint bshift, bsize; - uint gshift, gsize; - - display_GetColorBits(mode16.rmask, &rshift, &rsize); - display_GetColorBits(mode16.bmask, &bshift, &bsize); - display_GetColorBits(mode16.gmask, &gshift, &gsize); - - for(uint index = 0; index < 256; index++) { - word r = ((palette_data[(index * 3) + 0] * (1 << rsize)) / 256) << rshift; - word g = ((palette_data[(index * 3) + 1] * (1 << gsize)) / 256) << gshift; - word b = ((palette_data[(index * 3) + 2] * (1 << bsize)) / 256) << bshift; - display_palette16[index] = r | g | b; - } - - return true; -} - -// ---------------------------------------------------------------------------- -// ResetPalette24 -// ---------------------------------------------------------------------------- -static void display_ResetPalette24( ) { - for(uint index = 0; index < 256; index++) { - display_palette24[(index * 3) + 0] = palette_data[(index * 3) + 2]; - display_palette24[(index * 3) + 1] = palette_data[(index * 3) + 1]; - display_palette24[(index * 3) + 2] = palette_data[(index * 3) + 0]; - } -} - -// ---------------------------------------------------------------------------- -// ResetPalette32 -// ---------------------------------------------------------------------------- -static void display_ResetPalette32( ) { - for(uint index = 0; index < 256; index++) { - uint r = palette_data[(index * 3) + 0] << 16; - uint g = palette_data[(index * 3) + 1] << 8; - uint b = palette_data[(index * 3) + 2]; - display_palette32[index] = r | g | b; - } -} - -// ---------------------------------------------------------------------------- -// ReleaseDirectDraw -// ---------------------------------------------------------------------------- -static void display_ReleaseDirectDraw( ) { - if(display_ddraw != NULL) { - display_ddraw->Release( ); - display_ddraw = NULL; - } -} - -// ---------------------------------------------------------------------------- -// ReleasePrimary -// ---------------------------------------------------------------------------- -static void display_ReleasePrimary( ) { - if(display_primary != NULL) { - display_primary->SetPalette(NULL); - display_primary->SetClipper(NULL); - display_primary->Release( ); - display_primary = NULL; - } -} - -// ---------------------------------------------------------------------------- -// ReleaseOffscreen -// ---------------------------------------------------------------------------- -static void display_ReleaseOffscreen( ) { - if(display_offscreen != NULL) { - display_offscreen->Release( ); - display_offscreen = NULL; - } -} - -// ---------------------------------------------------------------------------- -// ReleasePalette -// ---------------------------------------------------------------------------- -static void display_ReleasePalette( ) { - if(display_palette != NULL) { - display_palette->Release( ); - display_palette = NULL; - } -} - -// ---------------------------------------------------------------------------- -// ReleaseClipper -// ---------------------------------------------------------------------------- -static void display_ReleaseClipper( ) { - if(display_clipper != NULL) { - display_clipper->Release( ); - display_clipper = NULL; - } -} - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -bool display_Initialize(HWND hWnd) { - if(hWnd == NULL) { - logger_LogError(IDS_DISPLAY12,""); - return false; - } - - HRESULT hr = DirectDrawCreate(NULL, &display_ddraw, NULL); - if(FAILED(hr) || display_ddraw == NULL) { - logger_LogError(IDS_DISPLAY13,""); - logger_LogError("",common_Format(hr)); - return false; - } - - display_modes.clear( ); - hr = display_ddraw->EnumDisplayModes(DDEDM_STANDARDVGAMODES, NULL, NULL, display_EnumerateModes); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY14,""); - logger_LogError("",common_Format(hr)); - return false; - } - - display_ReleaseDirectDraw( ); - display_hWnd = hWnd; - return true; -} - -// ---------------------------------------------------------------------------- -// SetFullscreen -// ---------------------------------------------------------------------------- -bool display_SetFullscreen( ) { - display_Release( ); - - HRESULT hr = DirectDrawCreate(NULL, &display_ddraw, NULL); - if(FAILED(hr) || display_ddraw == NULL) { - logger_LogError(IDS_DISPLAY13,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = display_ddraw->SetCooperativeLevel(display_hWnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY15,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = display_ddraw->SetDisplayMode(display_mode.width, display_mode.height, display_mode.bpp); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY16, common_Format(display_mode.width) + "x" + common_Format(display_mode.height) + "x" + common_Format(display_mode.bpp) + "."); - logger_LogError("",common_Format(hr)); - return false; - } - - DDSURFACEDESC primaryDesc = {0}; - primaryDesc.dwSize = sizeof(DDSURFACEDESC); - primaryDesc.dwFlags = DDSD_CAPS; - primaryDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - hr = display_ddraw->CreateSurface(&primaryDesc, &display_primary, NULL); - if(FAILED(hr) || display_primary == NULL) { - logger_LogError(IDS_DISPLAY17,""); - logger_LogError("",common_Format(hr)); - return false; - } - - DDSURFACEDESC offscreenDesc = {0}; - offscreenDesc.dwSize = sizeof(DDSURFACEDESC); - offscreenDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; - offscreenDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - offscreenDesc.dwWidth = DISPLAY_LENGTH; - - offscreenDesc.dwHeight = DISPLAY_HEIGHT; - - hr = display_ddraw->CreateSurface(&offscreenDesc, &display_offscreen, NULL); - if(FAILED(hr) || display_offscreen == NULL) { - logger_LogError(IDS_DISPLAY18,""); - logger_LogError("",common_Format(hr)); - return false; - } - - if(!display_SetClipper( )) { - logger_LogError(IDS_DISPLAY19,""); - return false; - } - - if(display_mode.bpp == 8) { - PALETTEENTRY paletteEntry[256] = {0}; - hr = display_ddraw->CreatePalette(DDPCAPS_8BIT, paletteEntry, &display_palette, NULL); - if(FAILED(hr) || display_palette == NULL) { - logger_LogError(IDS_DISPLAY20,""); - logger_LogError("",common_Format(hr)); - return false; - } - hr = display_primary->SetPalette(display_palette); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY21,""); - logger_LogError("",common_Format(hr)); - return false; - } - } - - display_fullscreen = true; - if(!display_ResetPalette( )) { - logger_LogError(IDS_DISPLAY22,""); - return false; - } - - return true; -} - -// ---------------------------------------------------------------------------- -// SetWindowed -// ---------------------------------------------------------------------------- -bool display_SetWindowed( ) { - display_Release( ); - - HRESULT hr = DirectDrawCreate(NULL, &display_ddraw, NULL); - if(FAILED(hr) || display_ddraw == NULL) { - logger_LogError(IDS_DISPLAY13,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = display_ddraw->SetCooperativeLevel(display_hWnd, DDSCL_NORMAL); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY23,""); - logger_LogError("",common_Format(hr)); - return false; - } - - DDSURFACEDESC primaryDesc = {0}; - primaryDesc.dwSize = sizeof(DDSURFACEDESC); - primaryDesc.dwFlags = DDSD_CAPS; - primaryDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - hr = display_ddraw->CreateSurface(&primaryDesc, &display_primary, NULL); - if(FAILED(hr) || display_primary == NULL) { - logger_LogError(IDS_DISPLAY17,""); - logger_LogError("",common_Format(hr)); - return false; - } - - DDSURFACEDESC offscreenDesc = {0}; - offscreenDesc.dwSize = sizeof(DDSURFACEDESC); - offscreenDesc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; - offscreenDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - offscreenDesc.dwWidth = DISPLAY_LENGTH; - offscreenDesc.dwHeight = DISPLAY_HEIGHT; - - hr = display_ddraw->CreateSurface(&offscreenDesc, &display_offscreen, NULL); - if(FAILED(hr) || display_offscreen == NULL) { - logger_LogError(IDS_DISPLAY24,""); - logger_LogError("",common_Format(hr)); - return false; - } - - if(!display_SetClipper( )) { - logger_LogError(IDS_DISPLAY19,""); - return false; - } - - display_fullscreen = false; - if(!display_ResetPalette( )) { - logger_LogError(IDS_DISPLAY22,""); - return false; - } - - return true; -} - -// ---------------------------------------------------------------------------- -// Show -// ---------------------------------------------------------------------------- -bool display_Show( ) { - if(display_ddraw == NULL) { - logger_LogError(IDS_DISPLAY6,""); - return false; - } - if(display_offscreen == NULL) { - logger_LogError(IDS_DISPLAY8,""); - return false; - } - if(display_primary == NULL) { - logger_LogError(IDS_DISPLAY7,""); - return false; - } - - uint height = maria_visibleArea.GetHeight( ); - uint length = maria_visibleArea.GetLength( ); - - DDSURFACEDESC offscreenDesc = {0}; - offscreenDesc.dwSize = sizeof(DDSURFACEDESC); - HRESULT hr = display_offscreen->Lock(NULL, &offscreenDesc, DDLOCK_WAIT, NULL); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY25,""); - logger_LogError("",common_Format(hr)); - if(hr != DDERR_SURFACELOST || !display_RestoreOffscreen( )) { - return false; - } - } - - const byte* buffer = maria_surface + ((maria_visibleArea.top - maria_displayArea.top) * maria_visibleArea.GetLength( )); - - if(offscreenDesc.ddpfPixelFormat.dwRGBBitCount == 8) { - byte* surface = (byte*)offscreenDesc.lpSurface; - for(uint indexY = 0; indexY < height; indexY++) { - for(uint indexX = 0; indexX < length; indexX += 4) { - surface[indexX + 0] = buffer[indexX + 0]; - surface[indexX + 1] = buffer[indexX + 1]; - surface[indexX + 2] = buffer[indexX + 2]; - surface[indexX + 3] = buffer[indexX + 3]; - } - surface += offscreenDesc.lPitch; - buffer += length; - } - } - else if(offscreenDesc.ddpfPixelFormat.dwRGBBitCount == 16) { - word* surface = (word*)offscreenDesc.lpSurface; - uint pitch = offscreenDesc.lPitch >> 1; - for(uint indexY = 0; indexY < height; indexY++) { - for(uint indexX = 0; indexX < length; indexX += 4) { - surface[indexX + 0] = display_palette16[buffer[indexX + 0]]; - surface[indexX + 1] = display_palette16[buffer[indexX + 1]]; - surface[indexX + 2] = display_palette16[buffer[indexX + 2]]; - surface[indexX + 3] = display_palette16[buffer[indexX + 3]]; - } - surface += pitch; - buffer += length; - } - } - else if(offscreenDesc.ddpfPixelFormat.dwRGBBitCount == 24) { - byte* surface = (byte*)offscreenDesc.lpSurface; - for(uint indexY = 0; indexY < height; indexY++) { - for(uint indexX = 0; indexX < length; indexX++) { - surface[(indexX * 3) + 0] = display_palette24[(buffer[indexX] * 3) + 0]; - surface[(indexX * 3) + 1] = display_palette24[(buffer[indexX] * 3) + 1]; - surface[(indexX * 3) + 2] = display_palette24[(buffer[indexX] * 3) + 2]; - } - surface += offscreenDesc.lPitch; - buffer += length; - } - } - else if(offscreenDesc.ddpfPixelFormat.dwRGBBitCount == 32) { - uint* surface = (uint*)offscreenDesc.lpSurface; - uint pitch = offscreenDesc.lPitch >> 2; - for(uint indexY = 0; indexY < height; indexY++) { - for(uint indexX = 0; indexX < length; indexX += 4) { - surface[indexX + 0] = display_palette32[buffer[indexX + 0]]; - surface[indexX + 1] = display_palette32[buffer[indexX + 1]]; - surface[indexX + 2] = display_palette32[buffer[indexX + 2]]; - surface[indexX + 3] = display_palette32[buffer[indexX + 3]]; - } - surface += pitch; - buffer += length; - } - } - - hr = display_offscreen->Unlock(NULL); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY26,""); - logger_LogError("",common_Format(hr)); - if(hr != DDERR_SURFACELOST || !display_RestoreOffscreen( )) { - return false; - } - } - - RECT targetRect = (display_stretched)? display_GetStretchedRect( ): display_GetCenteredRect( ); - RECT sourceRect = {0, 0, maria_visibleArea.GetLength( ), maria_visibleArea.GetHeight( )}; - - hr = display_primary->Blt(&targetRect, display_offscreen, &sourceRect, DDBLT_WAIT, NULL); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY27,""); - logger_LogError("",common_Format(hr)); - if(hr != DDERR_SURFACELOST || !display_RestorePrimary( )) { - return false; - } - } - - return true; -} - -// ---------------------------------------------------------------------------- -// ResetPalette -// ---------------------------------------------------------------------------- -bool display_ResetPalette( ) { - display_ResetPalette24( ); - display_ResetPalette32( ); - if(!display_ResetPalette16( )) { - logger_LogError(IDS_DISPLAY28,""); - return false; - } - if(display_fullscreen && !display_ResetPalette08( )) { - logger_LogError(IDS_DISPLAY29,""); - return false; - } - return true; -} - -// ---------------------------------------------------------------------------- -// TakeScreenshot -// ---------------------------------------------------------------------------- -bool display_TakeScreenshot(std::string filename) { - if(filename.empty( ) || filename.length == 0) { - logger_LogError(IDS_DISPLAY30,""); - return false; - } - - BITMAPFILEHEADER bitmapFileHeader = {0}; - bitmapFileHeader.bfType = 0x4d42; - bitmapFileHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (maria_visibleArea.GetArea( ) * 3); - bitmapFileHeader.bfReserved1 = 0; - bitmapFileHeader.bfReserved2 = 0; - bitmapFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); - - BITMAPINFOHEADER bitmapInfoHeader = {0}; - bitmapInfoHeader.biSize = sizeof(BITMAPINFOHEADER); - bitmapInfoHeader.biWidth = maria_visibleArea.GetLength( ); - bitmapInfoHeader.biHeight = maria_visibleArea.GetHeight( ); - bitmapInfoHeader.biPlanes = 1; - bitmapInfoHeader.biBitCount = 24; - - FILE* file = fopen(filename.c_str( ), "wb"); - if(file == NULL) { - logger_LogError(IDS_DISPLAY31, filename); - return false; - } - - fwrite(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, file); - fwrite(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, file); - - const byte* buffer = maria_surface + (maria_visibleArea.top - maria_displayArea.top) * maria_visibleArea.GetLength( ); - - for(int row = maria_visibleArea.GetHeight( ) - 1; row >= 0; row--) { - for(uint column = 0; column < maria_visibleArea.GetLength( ); column++) { - byte entry = buffer[(row * maria_visibleArea.GetLength( )) + column]; - fwrite(&palette_data[(entry * 3) + 2], 1, 1, file); - fwrite(&palette_data[(entry * 3) + 1], 1, 1, file); - fwrite(&palette_data[(entry * 3) + 0], 1, 1, file); - } - } - - fclose(file); - return true; -} - -// ---------------------------------------------------------------------------- -// Clear -// ---------------------------------------------------------------------------- -bool display_Clear( ) { - if(display_ddraw == NULL) { - logger_LogError(IDS_DISPLAY6,""); - return false; - } - if(display_offscreen == NULL) { - logger_LogError(IDS_DISPLAY8,""); - return false; - } - if(display_primary == NULL) { - logger_LogError(IDS_DISPLAY7,""); - return false; - } - - DDBLTFX bltFx; - bltFx.dwSize = sizeof(DDBLTFX); - bltFx.dwFillColor = 0; - - HRESULT hr = display_offscreen->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &bltFx); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY32,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = display_primary->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &bltFx); - if(FAILED(hr)) { - logger_LogError(IDS_DISPLAY33,""); - logger_LogError("",common_Format(hr)); - return false; - } - - return true; -} - -// ---------------------------------------------------------------------------- -// IsFullscreen -// ---------------------------------------------------------------------------- -bool display_IsFullscreen( ) { - return display_fullscreen; -} - -// ---------------------------------------------------------------------------- -// Release -// ---------------------------------------------------------------------------- -void display_Release( ) { - display_ReleaseClipper( ); - display_ReleasePalette( ); - display_ReleaseOffscreen( ); - display_ReleasePrimary( ); - display_ReleaseDirectDraw( ); -} diff --git a/Win/Display.h b/Win/Display.h deleted file mode 100755 index 2779671..0000000 --- a/Win/Display.h +++ /dev/null @@ -1,66 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Display.h -// ---------------------------------------------------------------------------- -#ifndef DISPLAY_H -#define DISPLAY_H -#define NULL 0 - -#include -#include -#include -#include "Palette.h" -#include "Maria.h" -#include "Common.h" -#include "Logger.h" - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -struct Mode { - uint width; - uint height; - uint bpp; - uint rmask; - uint gmask; - uint bmask; -}; - -extern bool display_Initialize(HWND hWnd); -extern bool display_SetFullscreen( ); -extern bool display_SetWindowed( ); -extern bool display_Show( ); -extern bool display_ResetPalette( ); -extern bool display_TakeScreenshot(std::string filename); -extern bool display_Clear( ); -extern bool display_IsFullscreen( ); -extern void display_Release( ); -extern bool display_stretched; -extern bool display_fullscreen; -extern bool display_menuenabled; -extern byte display_zoom; -extern std::vector display_modes; -extern Mode display_mode; - -#endif diff --git a/Win/Help.cpp b/Win/Help.cpp deleted file mode 100755 index cef4481..0000000 --- a/Win/Help.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Help.cpp -// ---------------------------------------------------------------------------- -#include "Help.h" - -static std::string help_filename; -static HWND common_hWnd = NULL; - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -void help_Initialize(HWND hWnd) { - help_filename = common_defaultPath + "ProSystem.chm"; - common_hWnd = hWnd; -} - -// ---------------------------------------------------------------------------- -// ShowContents -// ---------------------------------------------------------------------------- -void help_ShowContents( ) { - HtmlHelp(common_hWnd, help_filename.c_str( ), HH_DISPLAY_TOC, NULL); -} - -// ---------------------------------------------------------------------------- -// ShowIndex -// ---------------------------------------------------------------------------- -void help_ShowIndex( ) { - HtmlHelp(common_hWnd, help_filename.c_str( ), HH_DISPLAY_INDEX, NULL); -} - diff --git a/Win/Help.h b/Win/Help.h deleted file mode 100755 index 095944f..0000000 --- a/Win/Help.h +++ /dev/null @@ -1,42 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Help.h -// ---------------------------------------------------------------------------- -#ifndef HELP_H -#define HELP_H -#define NULL 0 - -#include -#include -#include "Htmlhelp.h" -#include "Common.h" - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern void help_Initialize(HWND hWnd); -extern void help_ShowContents( ); -extern void help_ShowIndex( ); - -#endif \ No newline at end of file diff --git a/Win/Input.cpp b/Win/Input.cpp deleted file mode 100755 index 6ae5891..0000000 --- a/Win/Input.cpp +++ /dev/null @@ -1,1350 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Input.cpp -// ---------------------------------------------------------------------------- -#include -#include "Input.h" -#include "Console.h" -#define INPUT_KEY_SIZE 100 -#define INPUT_JOY_SIZE 20 - -byte input_keys[17] = {DIK_RIGHT, DIK_LEFT, DIK_DOWN, DIK_UP, DIK_X, DIK_Z, DIK_L, DIK_J, DIK_K, DIK_I, DIK_M, DIK_N, DIK_F2, DIK_F3, DIK_F4, DIK_F5, DIK_F6}; -byte input_values[17] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; -byte input_devices[17] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - -byte user_keys[2] = {DIK_ESCAPE, DIK_F4}; -byte user_values[2] = {0,0}; -byte user_devices[2] = {0,0}; -byte user_modifiers[2] = {0,DIK_LALT}; - -static LPDIRECTINPUT input_dinput = NULL; -static LPDIRECTINPUTDEVICE2 input_joystick[128] = {NULL,NULL}; -static LPDIRECTINPUTDEVICE input_keyboard = NULL; -extern const std::string input_keyTitles[ ]; -extern const byte input_keyValues[ ]; -extern const std::string input_joyTitles[ ]; -extern const byte input_joyValues[ ]; -HINSTANCE input_hInstance; -static int current_device; - -BOOL CALLBACK InitJoysticksCallback(const DIDEVICEINSTANCE* - pdidInstance, VOID* pContext); -void input_GetJoystickPartState ( byte part, byte *state, DIJOYSTATE *js ); - -// ---------------------------------------------------------------------------- -// InitializeKeys -// ---------------------------------------------------------------------------- -static void input_InitializeKeys(HWND hCombo, int value) { - if ( !value ) { - for(int index = 0; index < INPUT_KEY_SIZE; index++) { - SendMessage(hCombo, CB_INSERTSTRING, index, (LPARAM)input_keyTitles[index].c_str( )); - SendMessage(hCombo, CB_SETITEMDATA, index, input_keyValues[index]); - } - } - else { - for(int index = 0; index < INPUT_JOY_SIZE; index++) { - SendMessage(hCombo, CB_INSERTSTRING, index, (LPARAM)input_joyTitles[index].c_str( )); - SendMessage(hCombo, CB_SETITEMDATA, index, input_joyValues[index]); - } - } -} - -// ---------------------------------------------------------------------------- -// SelectKey -// ---------------------------------------------------------------------------- -static void input_SelectKey(HWND hCombo, int value) { - for(int index = 0; index < INPUT_KEY_SIZE; index++) { - if(SendMessage(hCombo, CB_GETITEMDATA, index, 0) == value) { - SendMessage(hCombo, CB_SETCURSEL, index, 0); - return; - } - } -} - -// ---------------------------------------------------------------------------- -// InitializeModifiers -// ---------------------------------------------------------------------------- -static void input_InitializeModifiers(HWND hCombo, int value) { - - if ( value ) { - SendMessage(hCombo, CB_SHOWDROPDOWN, false, 0); - SendMessage(hCombo, CB_RESETCONTENT, 0, 0); - } - else { - SendMessage(hCombo, CB_SHOWDROPDOWN, true, 0); - SendMessage(hCombo, CB_INSERTSTRING, 0, (LPARAM)"None"); - SendMessage(hCombo, CB_SETITEMDATA, 0, 0); - SendMessage(hCombo, CB_INSERTSTRING, 1, (LPARAM)"Shift"); - SendMessage(hCombo, CB_SETITEMDATA, 1, DIK_LSHIFT); - SendMessage(hCombo, CB_INSERTSTRING, 2, (LPARAM)"Alt"); - SendMessage(hCombo, CB_SETITEMDATA, 2, DIK_LALT); - SendMessage(hCombo, CB_INSERTSTRING, 3, (LPARAM)"Ctrl"); - SendMessage(hCombo, CB_SETITEMDATA, 3, DIK_LCONTROL); - } -} - -// ---------------------------------------------------------------------------- -// SelectModifier -// ---------------------------------------------------------------------------- -static void input_SelectModifier(HWND hCombo, int value) { - for(int index = 0; index < 4; index++) { - if(SendMessage(hCombo, CB_GETITEMDATA, index, 0) == value) { - SendMessage(hCombo, CB_SETCURSEL, index, 0); - return; - } - } -} - -// ---------------------------------------------------------------------------- -// AddDevice -// ---------------------------------------------------------------------------- -static void input_AddDevice(HWND hCombo, char *string, unsigned int value) { - - int index; - - index = SendMessage(hCombo, CB_INSERTSTRING, -1, (LPARAM)string); - SendMessage(hCombo, CB_SETITEMDATA, index, value); -} - -// ---------------------------------------------------------------------------- -// SelectDevice -// ---------------------------------------------------------------------------- -static void input_SelectDevice(HWND hCombo, int value) { - - int count = SendMessage(hCombo, CB_GETCOUNT, 0, 0); - - for(int index = 0; index < count; index++) { - if(SendMessage(hCombo, CB_GETITEMDATA, index, 0) == value) { - SendMessage(hCombo, CB_SETCURSEL, index, 0); - return; - } - } -} - -// ---------------------------------------------------------------------------- -// HasKeyValue -// ---------------------------------------------------------------------------- -static bool input_HasKeyValue(int value) { - for(int index = 0; index < 17; index++) { - if(input_keys[index] == value) { - return true; - } - } - return false; -} - -// ---------------------------------------------------------------------------- -// InitJoysticksListControl -// ---------------------------------------------------------------------------- -BOOL CALLBACK InitJoysticksListControl(const DIDEVICEINSTANCE* - pdidInstance, VOID* pContext) { - - // Add to Our Device List - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_UP), - (char *)pdidInstance->tszInstanceName, ++current_device ); - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_DOWN), - (char *)pdidInstance->tszInstanceName, current_device ); - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_LEFT), - (char *)pdidInstance->tszInstanceName, current_device ); - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_RIGHT), - (char *)pdidInstance->tszInstanceName, current_device ); - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_BUTTON1), - (char *)pdidInstance->tszInstanceName, current_device ); - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_BUTTON2), - (char *)pdidInstance->tszInstanceName, current_device ); - - return DIENUM_CONTINUE; -} - -// ---------------------------------------------------------------------------- -// InitJoysticksListConsole -// ---------------------------------------------------------------------------- -BOOL CALLBACK InitJoysticksListConsole(const DIDEVICEINSTANCE* - pdidInstance, VOID* pContext) { - // Add to Our Device List - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_RESET), - (char *)pdidInstance->tszInstanceName, ++current_device ); - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_SELECT), - (char *)pdidInstance->tszInstanceName, current_device ); - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_PAUSE), - (char *)pdidInstance->tszInstanceName, current_device ); - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_LEFTD), - (char *)pdidInstance->tszInstanceName, current_device ); - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_RIGHTD), - (char *)pdidInstance->tszInstanceName, current_device ); - - return DIENUM_CONTINUE; -} - -// ---------------------------------------------------------------------------- -// InitJoysticksListUser -// ---------------------------------------------------------------------------- -BOOL CALLBACK InitJoysticksListUser(const DIDEVICEINSTANCE* - pdidInstance, VOID* pContext) { - // Add to Our Device List - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_MENU), - (char *)pdidInstance->tszInstanceName, ++current_device ); - input_AddDevice (GetDlgItem((HWND)pContext, IDC_COMBO_DEVICE_EXIT), - (char *)pdidInstance->tszInstanceName, current_device ); - - return DIENUM_CONTINUE; -} - -// ---------------------------------------------------------------------------- -// InitializeControllerDialog -// ---------------------------------------------------------------------------- -static input_InitializeControllerDialog(HWND hDialog, byte controller) { - std::string title = "Controller " + common_Format(controller); - HWND hCombo; - int i; - int value,index; - int id_key[] = {3,2,1,0,4,5}; - int id[] = {IDC_COMBO_CONTROLLER_UP,IDC_COMBO_CONTROLLER_DOWN, - IDC_COMBO_CONTROLLER_LEFT,IDC_COMBO_CONTROLLER_RIGHT, - IDC_COMBO_CONTROLLER_BUTTON1,IDC_COMBO_CONTROLLER_BUTTON2}; - int id_device[] = {IDC_COMBO_DEVICE_UP,IDC_COMBO_DEVICE_DOWN, - IDC_COMBO_DEVICE_LEFT,IDC_COMBO_DEVICE_RIGHT, - IDC_COMBO_DEVICE_BUTTON1,IDC_COMBO_DEVICE_BUTTON2}; - - SetWindowText(hDialog, title.c_str( )); - - controller--; - - // Add Keyboard to Device List - for ( i = 0; i < 6; ++i ) - input_AddDevice(GetDlgItem(hDialog, id_device[i]), "Keyboard", 0); - - // First find joysticks, if any, callback adds to list - current_device = 0; - if ( input_dinput != NULL ) - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksListControl, - hDialog, DIEDFL_ATTACHEDONLY); - - // Select Keyboard or Joystick Device - for ( i = 0; i < 6; ++i ) { - index = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_SETCURSEL, (LPARAM)input_devices[id_key[i] + (6 * controller)], 0); - if(index != CB_ERR) { - value = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_GETITEMDATA, index, 0); - input_devices[id_key[i] + (6 * controller)] = value; - } - else { - index = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_GETCOUNT, 0, 0 ); - SendMessage(GetDlgItem(hDialog, id_device[i]), CB_SETCURSEL, index-1, 0 ); - value = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_GETITEMDATA, index-1, 0); - input_devices[id_key[i] + (6 * controller)] = value; - } - } - - // Initialize parts list based on selected device - for ( i = 0; i < 6; ++i ) { - input_InitializeKeys(hCombo = GetDlgItem(hDialog, id[i]), input_devices[id_key[i] + (6 * controller)]); - input_SelectKey(hCombo, input_keys[id_key[i] + (6 * controller)]); - } -} - -// ---------------------------------------------------------------------------- -// SetControllerValues -// ---------------------------------------------------------------------------- -static void input_SetControllerValues(HWND hDialog, byte controller) { - - int i,value,index; - int id_key[] = {3,2,1,0,4,5}; - int id[] = {IDC_COMBO_CONTROLLER_UP,IDC_COMBO_CONTROLLER_DOWN, - IDC_COMBO_CONTROLLER_LEFT,IDC_COMBO_CONTROLLER_RIGHT, - IDC_COMBO_CONTROLLER_BUTTON1,IDC_COMBO_CONTROLLER_BUTTON2}; - int id_device[] = {IDC_COMBO_DEVICE_UP,IDC_COMBO_DEVICE_DOWN, - IDC_COMBO_DEVICE_LEFT,IDC_COMBO_DEVICE_RIGHT, - IDC_COMBO_DEVICE_BUTTON1,IDC_COMBO_DEVICE_BUTTON2}; - HWND hCombo; - - controller--; - - for ( i = 0; i < 17; ++i ) { - input_values[i] = 0; - } - - for ( i = 0; i < 6; ++i ) { - hCombo = GetDlgItem(hDialog, id[i]); - index = SendMessage(hCombo, CB_GETCURSEL, 0, 0); - if(index != CB_ERR) { - value = SendMessage(hCombo, CB_GETITEMDATA, index, 0); - //if(!input_HasKeyValue(value)) { - input_keys[id_key[i] + (6 * controller)] = value; - //} - } - - hCombo = GetDlgItem(hDialog, id_device[i]); - index = SendMessage(hCombo, CB_GETCURSEL, 0, 0); - if(index != CB_ERR) { - value = SendMessage(hCombo, CB_GETITEMDATA, index, 0); - input_devices[id_key[i] + (6 * controller)] = value; - } - } -} - -// ---------------------------------------------------------------------------- -// SetConsoleValues -// ---------------------------------------------------------------------------- -static void input_SetConsoleValues(HWND hDialog) { - - int i,value,index; - int id[] = {IDC_COMBO_CONSOLE_RESET,IDC_COMBO_CONSOLE_SELECT, - IDC_COMBO_CONSOLE_PAUSE,IDC_COMBO_CONSOLE_RIGHT, - IDC_COMBO_CONSOLE_LEFT}; - int id_device[] = {IDC_COMBO_DEVICE_RESET,IDC_COMBO_DEVICE_SELECT, - IDC_COMBO_DEVICE_PAUSE,IDC_COMBO_DEVICE_RIGHTD, - IDC_COMBO_DEVICE_LEFTD}; - HWND hCombo; - - for ( i = 0; i < 17; ++i ) { - input_values[i] = 0; - } - - for ( i = 0; i < 5; ++i ) { - hCombo = GetDlgItem(hDialog, id[i]); - index = SendMessage(hCombo, CB_GETCURSEL, 0, 0); - if(index != CB_ERR) { - value = SendMessage(hCombo, CB_GETITEMDATA, index, 0); - //if(!input_HasKeyValue(value)) { - input_keys[i+12] = value; - //} - } - - hCombo = GetDlgItem(hDialog, id_device[i]); - index = SendMessage(hCombo, CB_GETCURSEL, 0, 0); - if(index != CB_ERR) { - value = SendMessage(hCombo, CB_GETITEMDATA, index, 0); - input_devices[i+12] = value; - } - } -} - -// ---------------------------------------------------------------------------- -// SetUserValues -// ---------------------------------------------------------------------------- -static void input_SetUserValues(HWND hDialog) { - - int i,value,index; - int id[] = {IDC_COMBO_PART_MENU,IDC_COMBO_PART_EXIT}; - int id_device[] = {IDC_COMBO_DEVICE_MENU,IDC_COMBO_DEVICE_EXIT}; - int id_modifier[] = {IDC_COMBO_MOD_MENU,IDC_COMBO_MOD_EXIT}; - - HWND hCombo; - - for ( i = 0; i < 2; ++i ) { - user_values[i] = 0; - } - - for ( i = 0; i < 2; ++i ) { - hCombo = GetDlgItem(hDialog, id[i]); - index = SendMessage(hCombo, CB_GETCURSEL, 0, 0); - if(index != CB_ERR) { - value = SendMessage(hCombo, CB_GETITEMDATA, index, 0); - //if(!input_HasKeyValue(value)) { - user_keys[i] = value; - //} - } - - hCombo = GetDlgItem(hDialog, id_device[i]); - index = SendMessage(hCombo, CB_GETCURSEL, 0, 0); - if(index != CB_ERR) { - value = SendMessage(hCombo, CB_GETITEMDATA, index, 0); - user_devices[i] = value; - } - - hCombo = GetDlgItem(hDialog, id_modifier[i]); - index = SendMessage(hCombo, CB_GETCURSEL, 0, 0); - if(index != CB_ERR) { - value = SendMessage(hCombo, CB_GETITEMDATA, index, 0); - user_modifiers[i] = value; - } - } -} - -// ---------------------------------------------------------------------------- -// InitializeConsoleDialog -// ---------------------------------------------------------------------------- -static void input_InitializeConsoleDialog(HWND hDialog) { - - HWND hCombo; - int i; - int value,index; - int id[] = {IDC_COMBO_CONSOLE_RESET,IDC_COMBO_CONSOLE_SELECT, - IDC_COMBO_CONSOLE_PAUSE,IDC_COMBO_CONSOLE_RIGHT, - IDC_COMBO_CONSOLE_LEFT}; - int id_device[] = {IDC_COMBO_DEVICE_RESET,IDC_COMBO_DEVICE_SELECT, - IDC_COMBO_DEVICE_PAUSE,IDC_COMBO_DEVICE_RIGHTD, - IDC_COMBO_DEVICE_LEFTD}; - - // Add Keyboard to Device List - for ( i = 0; i < 5; ++i ) - input_AddDevice(GetDlgItem(hDialog, id_device[i]), "Keyboard", 0); - - // First find joysticks, if any, callback adds to list - current_device = 0; - if ( input_dinput != NULL ) - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksListConsole, - hDialog, DIEDFL_ATTACHEDONLY); - - // Select Keyboard or Joystick Device - for ( i = 0; i < 5; ++i ) { - index = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_SETCURSEL, (LPARAM)input_devices[i+12], 0); - if(index != CB_ERR) { - value = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_GETITEMDATA, index, 0); - input_devices[i+12] = value; - } - else { - index = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_GETCOUNT, 0, 0 ); - SendMessage(GetDlgItem(hDialog, id_device[i]), CB_SETCURSEL, index-1, 0 ); - value = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_GETITEMDATA, index-1, 0); - input_devices[i+12] = value; - } - } - - // Initialize parts list based on selected device - for ( i = 0; i < 5; ++i ) { - input_InitializeKeys(hCombo = GetDlgItem(hDialog, id[i]), input_devices[i+12]); - input_SelectKey(hCombo, input_keys[i+12]); - } -} - -// ---------------------------------------------------------------------------- -// InitializeUserDialog -// ---------------------------------------------------------------------------- -static void input_InitializeUserDialog(HWND hDialog) { - - HWND hCombo; - int i; - int value,index; - int id[] = {IDC_COMBO_PART_MENU,IDC_COMBO_PART_EXIT}; - int id_device[] = {IDC_COMBO_DEVICE_MENU,IDC_COMBO_DEVICE_EXIT}; - int id_modifier[] = {IDC_COMBO_MOD_MENU,IDC_COMBO_MOD_EXIT}; - - // Add Keyboard to Device List - for ( i = 0; i < 2; ++i ) - input_AddDevice(GetDlgItem(hDialog, id_device[i]), "Keyboard", 0); - - // First find joysticks, if any, callback adds to list - current_device = 0; - if ( input_dinput != NULL ) - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksListUser, - hDialog, DIEDFL_ATTACHEDONLY); - - // Select Keyboard or Joystick Device - for ( i = 0; i < 2; ++i ) { - index = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_SETCURSEL, (LPARAM)user_devices[i], 0); - if(index != CB_ERR) { - value = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_GETITEMDATA, index, 0); - user_devices[i] = value; - } - else { - index = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_GETCOUNT, 0, 0 ); - SendMessage(GetDlgItem(hDialog, id_device[i]), CB_SETCURSEL, index-1, 0 ); - value = SendMessage(GetDlgItem(hDialog, id_device[i]), CB_GETITEMDATA, index-1, 0); - user_devices[i] = value; - } - } - - // Initialize parts list based on selected device - for ( i = 0; i < 2; ++i ) { - input_InitializeKeys(hCombo = GetDlgItem(hDialog, id[i]), user_devices[i]); - input_SelectKey(hCombo, user_keys[i]); - } - - // Initialize modifier keys - for ( i = 0; i < 2; ++i ) { - input_InitializeModifiers(hCombo = GetDlgItem(hDialog, id_modifier[i]), user_devices[i]); - input_SelectModifier(hCombo, user_modifiers[i]); - } - -} - -// ---------------------------------------------------------------------------- -// Controller1Procedure -// ---------------------------------------------------------------------------- -static BOOL CALLBACK input_Controller1Procedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - - int value; - int index, id_index; - int id_key[] = {3,2,1,0,4,5}; - int id[] = {IDC_COMBO_CONTROLLER_UP,IDC_COMBO_CONTROLLER_DOWN, - IDC_COMBO_CONTROLLER_LEFT,IDC_COMBO_CONTROLLER_RIGHT, - IDC_COMBO_CONTROLLER_BUTTON1,IDC_COMBO_CONTROLLER_BUTTON2}; - - switch(message) { - case WM_INITDIALOG: - input_InitializeControllerDialog(hWnd, 1); - break; - case WM_COMMAND: - if(LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDC_BUTTON_CONTROLLER_CANCEL) { - input_ReleaseJoysticks(); - current_device = 0; - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksCallback, - NULL, DIEDFL_ATTACHEDONLY); - EndDialog(hWnd, 0); - return 1; - } - else if(LOWORD(wParam) == IDC_BUTTON_CONTROLLER_OK) { - input_SetControllerValues(hWnd, 1); - input_ReleaseJoysticks(); - current_device = 0; - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksCallback, - NULL, DIEDFL_ATTACHEDONLY); - EndDialog(hWnd, 0); - return 1; - } - - // Check for device change - bberlin - else if ( HIWORD(wParam) == CBN_SELCHANGE) { - index = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0); - value = SendMessage((HWND)lParam, CB_GETITEMDATA, index, 0); - - switch ( LOWORD(wParam) ) { - case IDC_COMBO_DEVICE_UP: id_index = 0; break; - case IDC_COMBO_DEVICE_DOWN: id_index = 1; break; - case IDC_COMBO_DEVICE_LEFT: id_index = 2; break; - case IDC_COMBO_DEVICE_RIGHT: id_index = 3; break; - case IDC_COMBO_DEVICE_BUTTON1: id_index = 4; break; - case IDC_COMBO_DEVICE_BUTTON2: id_index = 5; break; - default: return 0; break; - } - - if ( input_devices[id_key[id_index]] != value ) { - input_devices[id_key[id_index]] = value; - index = SendMessage(GetDlgItem(hWnd, id[id_index]), CB_RESETCONTENT, 0, 0); - input_InitializeKeys(GetDlgItem(hWnd, id[id_index]), value); - } - } - - break; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// Controller2Procedure -// ---------------------------------------------------------------------------- -static BOOL CALLBACK input_Controller2Procedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - - int value; - int index, id_index; - int id_key[] = {3,2,1,0,4,5}; - int id[] = {IDC_COMBO_CONTROLLER_UP,IDC_COMBO_CONTROLLER_DOWN, - IDC_COMBO_CONTROLLER_LEFT,IDC_COMBO_CONTROLLER_RIGHT, - IDC_COMBO_CONTROLLER_BUTTON1,IDC_COMBO_CONTROLLER_BUTTON2}; - - switch(message) { - case WM_INITDIALOG: - input_InitializeControllerDialog(hWnd, 2); - break; - case WM_COMMAND: - if(LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDC_BUTTON_CONTROLLER_CANCEL) { - input_ReleaseJoysticks(); - current_device = 0; - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksCallback, - NULL, DIEDFL_ATTACHEDONLY); - EndDialog(hWnd, 0); - return 1; - } - else if(LOWORD(wParam) == IDC_BUTTON_CONTROLLER_OK) { - input_SetControllerValues(hWnd, 2); - input_ReleaseJoysticks(); - current_device = 0; - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksCallback, - NULL, DIEDFL_ATTACHEDONLY); - EndDialog(hWnd, 0); - return 1; - } - - // Check for device change - bberlin - else if ( HIWORD(wParam) == CBN_SELCHANGE) { - index = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0); - value = SendMessage((HWND)lParam, CB_GETITEMDATA, index, 0); - - switch ( LOWORD(wParam) ) { - case IDC_COMBO_DEVICE_UP: id_index = 0; break; - case IDC_COMBO_DEVICE_DOWN: id_index = 1; break; - case IDC_COMBO_DEVICE_LEFT: id_index = 2; break; - case IDC_COMBO_DEVICE_RIGHT: id_index = 3; break; - case IDC_COMBO_DEVICE_BUTTON1: id_index = 4; break; - case IDC_COMBO_DEVICE_BUTTON2: id_index = 5; break; - default: return 0; break; - } - - if ( input_devices[id_key[id_index] + (6 * 1)] != value ) { - input_devices[id_key[id_index] + (6 * 1)] = value; - index = SendMessage(GetDlgItem(hWnd, id[id_index]), CB_RESETCONTENT, 0, 0); - input_InitializeKeys(GetDlgItem(hWnd, id[id_index]), value); - } - } - break; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// ConsoleProcedure -// ---------------------------------------------------------------------------- -static BOOL CALLBACK input_ConsoleProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - - int value; - int index, id_index; - int id[] = {IDC_COMBO_CONSOLE_RESET,IDC_COMBO_CONSOLE_SELECT, - IDC_COMBO_CONSOLE_PAUSE,IDC_COMBO_CONSOLE_RIGHT, - IDC_COMBO_CONSOLE_LEFT}; - - switch(message) { - case WM_INITDIALOG: - input_InitializeConsoleDialog(hWnd); - break; - case WM_COMMAND: - if(LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDC_BUTTON_CONSOLE_CANCEL) { - input_ReleaseJoysticks(); - current_device = 0; - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksCallback, - NULL, DIEDFL_ATTACHEDONLY); - EndDialog(hWnd, 0); - return 1; - } - else if(LOWORD(wParam) == IDC_BUTTON_CONSOLE_OK) { - input_SetConsoleValues(hWnd); - input_ReleaseJoysticks(); - current_device = 0; - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksCallback, - NULL, DIEDFL_ATTACHEDONLY); - EndDialog(hWnd, 0); - return 1; - } - - // Check for device change - bberlin - else if ( HIWORD(wParam) == CBN_SELCHANGE) { - index = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0); - value = SendMessage((HWND)lParam, CB_GETITEMDATA, index, 0); - - switch ( LOWORD(wParam) ) { - case IDC_COMBO_DEVICE_RESET: id_index = 0; break; - case IDC_COMBO_DEVICE_SELECT: id_index = 1; break; - case IDC_COMBO_DEVICE_PAUSE: id_index = 2; break; - case IDC_COMBO_DEVICE_RIGHTD: id_index = 3; break; - case IDC_COMBO_DEVICE_LEFTD: id_index = 4; break; - default: return 0; break; - } - - if ( input_devices[id_index+12] != value ) { - input_devices[id_index+12] = value; - index = SendMessage(GetDlgItem(hWnd, id[id_index]), CB_RESETCONTENT, 0, 0); - input_InitializeKeys(GetDlgItem(hWnd, id[id_index]), value); - } - } - - break; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// UserProcedure -// ---------------------------------------------------------------------------- -static BOOL CALLBACK input_UserProcedure(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - - int value; - int index, id_index; - int id[] = {IDC_COMBO_PART_MENU,IDC_COMBO_PART_EXIT}; - int id_modifier[] = {IDC_COMBO_MOD_MENU,IDC_COMBO_MOD_EXIT}; - - switch(message) { - case WM_INITDIALOG: - input_InitializeUserDialog(hWnd); - break; - case WM_COMMAND: - if(LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDC_BUTTON_USER_CANCEL) { - input_ReleaseJoysticks(); - current_device = 0; - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksCallback, - NULL, DIEDFL_ATTACHEDONLY); - EndDialog(hWnd, 0); - return 1; - } - else if(LOWORD(wParam) == IDC_BUTTON_USER_OK) { - input_SetUserValues(hWnd); - input_ReleaseJoysticks(); - current_device = 0; - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksCallback, - NULL, DIEDFL_ATTACHEDONLY); - EndDialog(hWnd, 0); - return 1; - } - - // Check for device change - bberlin - else if ( HIWORD(wParam) == CBN_SELCHANGE) { - index = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0); - value = SendMessage((HWND)lParam, CB_GETITEMDATA, index, 0); - - switch ( LOWORD(wParam) ) { - case IDC_COMBO_DEVICE_MENU: id_index = 0; break; - case IDC_COMBO_DEVICE_EXIT: id_index = 1; break; - default: return 0; break; - } - - if ( user_devices[id_index] != value ) { - user_devices[id_index] = value; - index = SendMessage(GetDlgItem(hWnd, id[id_index]), CB_RESETCONTENT, 0, 0); - input_InitializeKeys(GetDlgItem(hWnd, id[id_index]), value); - index = SendMessage(GetDlgItem(hWnd, id_modifier[id_index]), CB_RESETCONTENT, 0, 0); - input_InitializeModifiers(GetDlgItem(hWnd, id_modifier[id_index]), value); - } - } - - break; - } - return 0; -} - -// ---------------------------------------------------------------------------- -// InitJoysticksCallback -// ---------------------------------------------------------------------------- -BOOL CALLBACK InitJoysticksCallback(const DIDEVICEINSTANCE* - pdidInstance, VOID* pContext) { - int i, joy_index; - HRESULT hr; - bool needed = false; - LPDIRECTINPUTDEVICE2 *p_joystick; - LPDIRECTINPUTDEVICE p_dev; - DIPROPRANGE diprg; - - joy_index = -1; - if ( input_joystick[++joy_index] == NULL ) - p_joystick = &input_joystick[joy_index]; - else if ( input_joystick[++joy_index] == NULL ) - p_joystick = &input_joystick[joy_index]; - else - return DIENUM_STOP; - - ++current_device; - - // Check if we need this joystick - for ( i = 0; i < 17; ++i ) { - if ( input_devices[i] == current_device ) { - needed = true; - input_values[i] = joy_index; - } - } - - // Check if we need this joystick - for ( i = 0; i < 2; ++i ) { - if ( user_devices[i] == current_device ) { - needed = true; - user_values[i] = joy_index; - } - } - - // If not needed, continue to check joysticks - if ( !needed ) - return DIENUM_CONTINUE; - - // Obtain an interface to the enumerated joystick. - hr = input_dinput->CreateDevice(pdidInstance->guidInstance, - &p_dev, NULL); - if(FAILED(hr)) - return DIENUM_CONTINUE; - - /* Set joystick data format */ - hr = (p_dev)->SetDataFormat( &c_dfDIJoystick ); - if( FAILED(hr) ) - { - (p_dev)->Release( ); - p_dev = NULL; - return DIENUM_CONTINUE; - } - - /* Set the cooperative level */ - hr = (p_dev)->SetCooperativeLevel( (HWND)pContext, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND ); - if( FAILED(hr) ) - { - (p_dev)->Release( ); - p_dev = NULL; - return DIENUM_CONTINUE; - } - - /* Set X-axis range to (-1000 ... +1000) - This lets us test against 0 to see which way the s_anStick is pointed */ - diprg.diph.dwSize = sizeof(diprg); - diprg.diph.dwHeaderSize = sizeof(diprg.diph); - diprg.diph.dwObj = DIJOFS_X; - diprg.diph.dwHow = DIPH_BYOFFSET; - diprg.lMin = -1000; - diprg.lMax = +1000; - - hr= (p_dev)->SetProperty( DIPROP_RANGE, &diprg.diph ); - if( FAILED(hr) ) - { - (p_dev)->Release( ); - p_dev = NULL; - return DIENUM_CONTINUE; - } - - /* And again for Y-axis range */ - diprg.diph.dwObj = DIJOFS_Y; - - hr= (p_dev)->SetProperty( DIPROP_RANGE, &diprg.diph ); - if( FAILED(hr) ) - { - (p_dev)->Release( ); - p_dev = NULL; - return DIENUM_CONTINUE; - } - - hr = (p_dev)->QueryInterface (IID_IDirectInputDevice2, (LPVOID *)p_joystick ); - if( FAILED(hr) ) - { - (p_dev)->Release( ); - p_dev = NULL; - return DIENUM_CONTINUE; - } - - return DIENUM_CONTINUE; -} - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -bool input_Initialize(HWND hWnd, HINSTANCE hInstance) { - if(hWnd == NULL) { - logger_LogError(IDS_INPUT1,""); - } - if(hInstance == NULL) { - logger_LogError(IDS_INPUT2,""); - return false; - } - - HRESULT hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &input_dinput, NULL); - if(FAILED(hr) || input_dinput == NULL) { - logger_LogError(IDS_INPUT3,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = input_dinput->CreateDevice(GUID_SysKeyboard, &input_keyboard, NULL); - if(FAILED(hr) || input_keyboard == NULL) { - logger_LogError(IDS_INPUT4,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = input_keyboard->SetDataFormat(&c_dfDIKeyboard); - if(FAILED(hr)) { - logger_LogError(IDS_INPUT5,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = input_keyboard->SetCooperativeLevel(hWnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE); - if(FAILED(hr)) { - logger_LogError(IDS_INPUT6,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = input_keyboard->Acquire( ); - if(FAILED(hr)) { - logger_LogError(IDS_INPUT7,""); - logger_LogError("",common_Format(hr)); - return false; - } - - // Add JoyStick Input - bberlin - current_device = 0; - input_dinput->EnumDevices(DIDEVTYPE_JOYSTICK, InitJoysticksCallback, - NULL, DIEDFL_ATTACHEDONLY); - - return true; -} - -// ---------------------------------------------------------------------------- -// GetKeyboardState -// ---------------------------------------------------------------------------- -bool input_GetKeyboardState(byte* input) { - - int i; - DIJOYSTATE js; - byte user_go[2]; - - user_go[0] = 0; - user_go[1] = 0; - - if(input_dinput == NULL) { - logger_LogError(IDS_INPUT8,""); - return false; - } - if(input_keyboard == NULL) { - logger_LogError(IDS_INPUT9,""); - return false; - } - if(input == NULL) { - logger_LogError(IDS_INPUT10,""); - return false; - } - - byte keyboard[256]; - HRESULT hr = input_keyboard->GetDeviceState(256, keyboard); - if(FAILED(hr)) { - logger_LogError(IDS_INPUT11,""); - logger_LogError("",common_Format(hr)); - return false; - } - - // Check for User Keys - for(int index = 0; index < 2; index++) { - if ( !user_devices[index] ) { - if ( (keyboard[user_keys[index]]) ) { - if ( !user_modifiers[index] ) { - if ( !keyboard[DIK_LALT] && !keyboard[DIK_RALT] && - !keyboard[DIK_LCONTROL] && !keyboard[DIK_RCONTROL] && - !keyboard[DIK_LSHIFT] && !keyboard[DIK_RSHIFT] ) { - user_go[index] = 1; - } - } - else if ( (keyboard[user_modifiers[index]]) ) { - user_go[index] = 1; - } - else if ( (keyboard[user_modifiers[index]] == DIK_LALT) && - keyboard[DIK_RALT] ) { - user_go[index] = 1; - } - else if ( (keyboard[user_modifiers[index]] == DIK_LSHIFT) && - keyboard[DIK_RSHIFT] ) { - user_go[index] = 1; - } - else if ( (keyboard[user_modifiers[index]] == DIK_LCONTROL) && - keyboard[DIK_RCONTROL] ) { - user_go[index] = 1; - } - } - console_SetUserInput ( user_go, index ); - } - } - - - for(index = 0; index < 17; index++) { - if ( !input_devices[index] ) - input[index] = (keyboard[input_keys[index]])? 1: 0; - } - - for ( i = 0; i < 2; ++i ) { - // Get Joystick Input - if ( input_joystick[i] == NULL ) - break; - hr = input_joystick[i]->Poll(); - if(FAILED(hr)) { - hr = input_joystick[i]->Acquire(); - } - hr = input_joystick[i]->GetDeviceState(sizeof(DIJOYSTATE), &js); - if(FAILED(hr)) { - logger_LogError(IDS_INPUT12,""); - logger_LogError("",common_Format(hr)); - continue; - } - - // Check if we need the info - for(int index = 0; index < 17; index++) { - if ( input_devices[index] && input_values[index] == i ) { - input_GetJoystickPartState ( input_keys[index], &input[index], &js ); - } - } - - // Check if we need the info for user keys - for(index = 0; index < 2; index++) { - if ( user_devices[index] && user_values[index] == i ) { - input_GetJoystickPartState ( user_keys[index], &user_go[index], &js ); - console_SetUserInput ( user_go, index ); - } - } - - } /* end for PC joystick */ - - return true; -} - -void input_GetJoystickPartState ( byte part, byte *state, DIJOYSTATE *js ) { - switch ( part ) { - case JOY_AXIS_UP: - *state = ( js->lY < -500 ) ? 1: 0; - break; - case JOY_AXIS_DOWN: - *state = ( js->lY > 500 ) ? 1: 0; - break; - case JOY_AXIS_LEFT: - *state = ( js->lX < -500 ) ? 1: 0; - break; - case JOY_AXIS_RIGHT: - *state = ( js->lX > 500 ) ? 1: 0; - break; - case JOY_PAD_UP: - *state = ( (js->rgdwPOV[0] > 32000 && js->rgdwPOV[0] < 37000) || - (js->rgdwPOV[0] >= 0 && js->rgdwPOV[0] < 4600) ) ? 1: 0; - break; - case JOY_PAD_DOWN: - *state = (js->rgdwPOV[0] > 13400 && js->rgdwPOV[0] < 22600) ? 1: 0; - break; - case JOY_PAD_LEFT: - *state = (js->rgdwPOV[0] > 22400 && js->rgdwPOV[0] < 31600) ? 1: 0; - break; - case JOY_PAD_RIGHT: - *state = (js->rgdwPOV[0] > 4400 && js->rgdwPOV[0] < 13600) ? 1: 0; - break; - case JOY_BUTTON_1: - case JOY_BUTTON_2: - case JOY_BUTTON_3: - case JOY_BUTTON_4: - case JOY_BUTTON_5: - case JOY_BUTTON_6: - case JOY_BUTTON_7: - case JOY_BUTTON_8: - case JOY_BUTTON_9: - case JOY_BUTTON_10: - case JOY_BUTTON_11: - case JOY_BUTTON_12: - *state = ( js->rgbButtons[part-JOY_BUTTON_1] & 0x80 ) ? 1: 0; - break; - } -} - -// ---------------------------------------------------------------------------- -// Release -// ---------------------------------------------------------------------------- -void input_Release( ) { - if(input_dinput != NULL) { - input_dinput->Release( ); - input_dinput = NULL; - } - if(input_keyboard != NULL) { - input_keyboard->Release( ); - input_keyboard = NULL; - } - input_ReleaseJoysticks(); -} - -void input_ReleaseJoysticks( ) { - - int i; - - for ( i = 0; i < 2; ++i ) { - if(input_joystick[i] != NULL) { - input_joystick[i]->Unacquire( ); - input_joystick[i]->Release( ); - input_joystick[i] = NULL; - } - } -} - -// ---------------------------------------------------------------------------- -// ShowController1Dialog -// ---------------------------------------------------------------------------- -void input_ShowController1Dialog(HWND hWnd, HINSTANCE hInstance) { - DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_CONTROLLER), hWnd, (DLGPROC)input_Controller1Procedure); -} - -// ---------------------------------------------------------------------------- -// ShowController2Dialog -// ---------------------------------------------------------------------------- -void input_ShowController2Dialog(HWND hWnd, HINSTANCE hInstance) { - DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_CONTROLLER), hWnd, (DLGPROC)input_Controller2Procedure); -} - -// ---------------------------------------------------------------------------- -// ShowConsoleDialog -// ---------------------------------------------------------------------------- -void input_ShowConsoleDialog(HWND hWnd, HINSTANCE hInstance) { - DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_CONSOLE), hWnd, (DLGPROC)input_ConsoleProcedure); -} - -// ---------------------------------------------------------------------------- -// ShowConsoleDialog -// ---------------------------------------------------------------------------- -void input_ShowUserDialog(HWND hWnd, HINSTANCE hInstance) { - DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_USER), hWnd, (DLGPROC)input_UserProcedure); -} - -// ---------------------------------------------------------------------------- -// Key Titles -// ---------------------------------------------------------------------------- -const std::string input_keyTitles[ ] = { - "ESCAPE", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", - "0", - "MINUS", - "EQUALS", - "BACK", - "TAB", - "Q", - "W", - "E", - "R", - "T", - "Y", - "U", - "I", - "O", - "P", - "L BRACKET", - "R BRACKET", - "RETURN", - "L CONTROL", - "A", - "S", - "D", - "F", - "G", - "H", - "J", - "K", - "L", - "SEMICOLON", - "APOSTROPHE", - "GRAVE", - "L SHIFT", - "BACKSLASH", - "Z", - "X", - "C", - "V", - "B", - "N", - "M", - "COMMA", - "PERIOD", - "SLASH", - "R SHIFT", - "MULTIPLY", - "L ALT", - "SPACE", - "CAPS LOCK", - "F1", - "F2", - "F3", - "F4", - "F5", - "F6", - "F7", - "F8", - "F9", - "F10", - "NUMLOCK", - "SCROLL", - "NUMPAD 7", - "NUMPAD 8", - "NUMPAD 9", - "SUBTRACT", - "NUMPAD 4", - "NUMPAD 5", - "NUMPAD 6", - "ADD", - "NUMPAD 1", - "NUMPAD 2", - "NUMPAD 3", - "NUMPAD 0", - "DECIMAL", - "F11", - "F12", - "NUMPAD ENTER", - "R CONTROL", - "DIVIDE", - "R ALT", - "PAUSE", - "HOME", - "UP", - "PGUP", - "LEFT", - "RIGHT", - "END", - "DOWN", - "PGDN", - "INSERT", - "DELETE" -}; - -// ---------------------------------------------------------------------------- -// Key Values -// ---------------------------------------------------------------------------- -const byte input_keyValues[ ] = { - DIK_ESCAPE, - DIK_1, - DIK_2, - DIK_3, - DIK_4, - DIK_5, - DIK_6, - DIK_7, - DIK_8, - DIK_9, - DIK_0, - DIK_MINUS, - DIK_EQUALS, - DIK_BACK, - DIK_TAB, - DIK_Q, - DIK_W, - DIK_E, - DIK_R, - DIK_T, - DIK_Y, - DIK_U, - DIK_I, - DIK_O, - DIK_P, - DIK_LBRACKET, - DIK_RBRACKET, - DIK_RETURN, - DIK_LCONTROL, - DIK_A, - DIK_S, - DIK_D, - DIK_F, - DIK_G, - DIK_H, - DIK_J, - DIK_K, - DIK_L, - DIK_SEMICOLON, - DIK_APOSTROPHE, - DIK_GRAVE, - DIK_LSHIFT, - DIK_BACKSLASH, - DIK_Z, - DIK_X, - DIK_C, - DIK_V, - DIK_B, - DIK_N, - DIK_M, - DIK_COMMA, - DIK_PERIOD, - DIK_SLASH, - DIK_RSHIFT, - DIK_MULTIPLY, - DIK_LMENU, - DIK_SPACE, - DIK_CAPITAL, - DIK_F1, - DIK_F2, - DIK_F3, - DIK_F4, - DIK_F5, - DIK_F6, - DIK_F7, - DIK_F8, - DIK_F9, - DIK_F10, - DIK_NUMLOCK, - DIK_SCROLL, - DIK_NUMPAD7, - DIK_NUMPAD8, - DIK_NUMPAD9, - DIK_SUBTRACT, - DIK_NUMPAD4, - DIK_NUMPAD5, - DIK_NUMPAD6, - DIK_ADD, - DIK_NUMPAD1, - DIK_NUMPAD2, - DIK_NUMPAD3, - DIK_NUMPAD0, - DIK_DECIMAL, - DIK_F11, - DIK_F12, - DIK_NUMPADENTER, - DIK_RCONTROL, - DIK_DIVIDE, - DIK_RMENU, - DIK_PAUSE, - DIK_HOME, - DIK_UP, - DIK_PRIOR, - DIK_LEFT, - DIK_RIGHT, - DIK_END, - DIK_DOWN, - DIK_NEXT, - DIK_INSERT, - DIK_DELETE -}; - -// ---------------------------------------------------------------------------- -// Joy Titles -// ---------------------------------------------------------------------------- -const std::string input_joyTitles[ ] = { - "Axis Up", - "Axis Down", - "Axis Left", - "Axis Right", - "Pad Up", - "Pad Down", - "Pad Left", - "Pad Right", - "Button1", - "Button2", - "Button3", - "Button4", - "Button5", - "Button6", - "Button7", - "Button8", - "Button9", - "Button10", - "Button11", - "Button12" -}; - -// ---------------------------------------------------------------------------- -// Joy Values -// ---------------------------------------------------------------------------- -const byte input_joyValues[ ] = { - JOY_AXIS_UP, - JOY_AXIS_DOWN, - JOY_AXIS_LEFT, - JOY_AXIS_RIGHT, - JOY_PAD_UP, - JOY_PAD_DOWN, - JOY_PAD_LEFT, - JOY_PAD_RIGHT, - JOY_BUTTON_1, - JOY_BUTTON_2, - JOY_BUTTON_3, - JOY_BUTTON_4, - JOY_BUTTON_5, - JOY_BUTTON_6, - JOY_BUTTON_7, - JOY_BUTTON_8, - JOY_BUTTON_9, - JOY_BUTTON_10, - JOY_BUTTON_11, - JOY_BUTTON_12 -}; diff --git a/Win/Input.h b/Win/Input.h deleted file mode 100755 index 93b7554..0000000 --- a/Win/Input.h +++ /dev/null @@ -1,79 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Input.h -// ---------------------------------------------------------------------------- -#ifndef INPUT_H -#define INPUT_H -#ifndef DIRECTINPUT_VERSION -#define DIRECTINPUT_VERSION 0x0700 -#define NULL 0 -#endif - -typedef enum { - JOY_AXIS_UP, - JOY_AXIS_DOWN, - JOY_AXIS_LEFT, - JOY_AXIS_RIGHT, - JOY_PAD_UP, - JOY_PAD_DOWN, - JOY_PAD_LEFT, - JOY_PAD_RIGHT, - JOY_BUTTON_1, - JOY_BUTTON_2, - JOY_BUTTON_3, - JOY_BUTTON_4, - JOY_BUTTON_5, - JOY_BUTTON_6, - JOY_BUTTON_7, - JOY_BUTTON_8, - JOY_BUTTON_9, - JOY_BUTTON_10, - JOY_BUTTON_11, - JOY_BUTTON_12 -} e_joy_value; - -#include -#include -#include "Resource.h" -#include "Common.h" -#include "Logger.h" - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern bool input_Initialize(HWND hWnd, HINSTANCE hInstance); -extern bool input_GetKeyboardState(byte* input); -extern void input_Release( ); -extern void input_ReleaseJoysticks( ); -extern void input_ShowController1Dialog(HWND hWnd, HINSTANCE hInstance); -extern void input_ShowController2Dialog(HWND hWnd, HINSTANCE hInstance); -extern void input_ShowConsoleDialog(HWND hWnd, HINSTANCE hInstance); -extern void input_ShowUserDialog(HWND hWnd, HINSTANCE hInstance); -extern byte input_keys[17]; -extern byte input_devices[17]; -extern byte user_keys[2]; -extern byte user_devices[2]; -extern byte user_modifiers[2]; - -#endif diff --git a/Win/Main.cpp b/Win/Main.cpp deleted file mode 100755 index 82b0011..0000000 --- a/Win/Main.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Main.cpp -// ---------------------------------------------------------------------------- -#include -#include -#include "Console.h" -#include "Common.h" -#include "Logger.h" -#include "Input.h" -#define NULL 0 - -// ---------------------------------------------------------------------------- -// ParseDefaultPath -// ---------------------------------------------------------------------------- -void main_ParseDefaultPath( ) { - std::string commandLine = GetCommandLine( ); - if(commandLine[0] == '"') { - common_defaultPath = common_Remove(commandLine.substr(0, commandLine.find('"', 1)), '"'); - common_defaultPath = common_defaultPath.substr(0, common_defaultPath.rfind("\\") + 1); - } - else { - common_defaultPath = commandLine.substr(0, commandLine.find(' ')); - common_defaultPath = common_defaultPath.substr(0, common_defaultPath.rfind("\\") + 1); - } -} - -// ---------------------------------------------------------------------------- -// WinMain -// ---------------------------------------------------------------------------- -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR commandLine, int showCommand) { - main_ParseDefaultPath( ); - logger_Initialize(common_defaultPath + "ProSystem.log"); - logger_level = LOGGER_LEVEL_DEBUG; - - console_Initialize(hInstance, commandLine); - - console_Run( ); - - logger_Release( ); - return 1; -} diff --git a/Win/Menu.cpp b/Win/Menu.cpp deleted file mode 100755 index 05d0050..0000000 --- a/Win/Menu.cpp +++ /dev/null @@ -1,408 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Menu.cpp -// ---------------------------------------------------------------------------- -#include "Menu.h" - -HACCEL menu_hAccel = NULL; - -static HMENU menu_hMenu = NULL; -static HMENU menu_hFileMenu = NULL; -static HMENU menu_hOptionsMenu = NULL; -static HMENU menu_hRecentMenu = NULL; -static HMENU menu_hDisplayMenu = NULL; -static HMENU menu_hScreenshotMenu = NULL; -static HMENU menu_hModesMenu = NULL; -static HMENU menu_hSoundMenu = NULL; -static HMENU menu_hSampleRateMenu = NULL; -static HMENU menu_hLatencyMenu = NULL; -static HMENU menu_hEmulationMenu = NULL; -static HMENU menu_hFrameSkipMenu = NULL; -static HMENU menu_hRegionsMenu = NULL; -static HMENU menu_hInputMenu = NULL; -static HMENU menu_hHelpMenu = NULL; -static HWND menu_hWnd = NULL; - -// ---------------------------------------------------------------------------- -// RefreshDisplayMenu -// ---------------------------------------------------------------------------- -static void menu_RefreshDisplayMenu( ) { -//Leonis - CheckMenuItem(menu_hScreenshotMenu, 0, MF_BYPOSITION | ((screenshot1)? MF_CHECKED: MF_UNCHECKED)); - CheckMenuItem(menu_hScreenshotMenu, 1, MF_BYPOSITION | ((screenshot2)? MF_CHECKED: MF_UNCHECKED)); - - CheckMenuItem(menu_hDisplayMenu, 0, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hDisplayMenu, 2, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hDisplayMenu, 5, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hDisplayMenu, 6, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hDisplayMenu, 7, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hDisplayMenu, 8, MF_BYPOSITION | MF_UNCHECKED); - if(display_IsFullscreen( )) { - CheckMenuItem(menu_hDisplayMenu, 0, MF_BYPOSITION | MF_CHECKED); - } - if(display_stretched) { - CheckMenuItem(menu_hDisplayMenu, 2, MF_BYPOSITION | MF_CHECKED); - } - CheckMenuItem(menu_hDisplayMenu, display_zoom + 4, MF_BYPOSITION | MF_CHECKED); - - if(cartridge_IsLoaded( )) { - EnableMenuItem(menu_hDisplayMenu, 10, MF_BYPOSITION | MF_ENABLED); - } - else { - EnableMenuItem(menu_hDisplayMenu, 10, MF_BYPOSITION | MF_GRAYED); - } -} - -// ---------------------------------------------------------------------------- -// RefreshModesMenu -// ---------------------------------------------------------------------------- -static void menu_RefreshModesMenu( ) { - int count = GetMenuItemCount(menu_hModesMenu); - int index; - for(index = count - 1; index >= 0; index--) { - DeleteMenu(menu_hModesMenu, index, MF_BYPOSITION); - } - - count = 0; - for(index = 0; index < display_modes.size( ); index++) { - Mode mode = display_modes[index]; - if(mode.bpp == 8) { - std::string description = common_Format(mode.width) + " x " + common_Format(mode.height); - MENUITEMINFO item_info = {0}; - item_info.cbSize = sizeof(MENUITEMINFO); - item_info.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID; - item_info.dwItemData = (DWORD)&display_modes[index]; - item_info.dwTypeData = (char*)description.c_str( ); - item_info.wID = IDM_MODES_BASE + index; - InsertMenuItem(menu_hModesMenu, count, TRUE, &item_info); - if(display_mode.height == mode.height && display_mode.width == mode.width) { - CheckMenuItem(menu_hModesMenu, count, MF_BYPOSITION | MF_CHECKED); - } - count++; - } - } -} - -// ---------------------------------------------------------------------------- -// RefreshOptionsMenu -// ---------------------------------------------------------------------------- -static void menu_RefreshOptionsMenu( ) { - if(cartridge_IsLoaded( )) { - EnableMenuItem(menu_hOptionsMenu, 0, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(menu_hOptionsMenu, 1, MF_BYPOSITION | MF_ENABLED); - CheckMenuItem(menu_hOptionsMenu, 1, MF_BYPOSITION | ((prosystem_paused)? MF_CHECKED: MF_UNCHECKED)); - } - else { - EnableMenuItem(menu_hOptionsMenu, 0, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(menu_hOptionsMenu, 1, MF_BYPOSITION | MF_GRAYED); - CheckMenuItem(menu_hOptionsMenu, 1, MF_BYPOSITION | MF_UNCHECKED); - } -} - -// ---------------------------------------------------------------------------- -// RefreshRecentMenu -// ---------------------------------------------------------------------------- -static void menu_RefreshRecentMenu( ) { - for(uint slot = 0; slot < 10; slot++) { - ModifyMenu(menu_hRecentMenu, slot, MF_BYPOSITION, IDM_RECENT_SLOT0 + slot, std::string("&" + common_Format(slot) + " " + console_recent[slot]).c_str( )); - } -} - -// ---------------------------------------------------------------------------- -// RefreshSoundMenu -// ---------------------------------------------------------------------------- -static void menu_RefreshSoundMenu( ) { - CheckMenuItem(menu_hSoundMenu, 0, MF_BYPOSITION | ((sound_IsMuted( ))? MF_CHECKED: MF_UNCHECKED)); - - CheckMenuItem(menu_hSampleRateMenu, 0, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hSampleRateMenu, 1, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hSampleRateMenu, 2, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hSampleRateMenu, 3, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hSampleRateMenu, 4, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hSampleRateMenu, 5, MF_BYPOSITION | MF_UNCHECKED); - - switch(sound_GetSampleRate( )) { - case 11025: - CheckMenuItem(menu_hSampleRateMenu, 0, MF_BYPOSITION | MF_CHECKED); - break; - case 22050: - CheckMenuItem(menu_hSampleRateMenu, 1, MF_BYPOSITION | MF_CHECKED); - break; - case 31440: - CheckMenuItem(menu_hSampleRateMenu, 2, MF_BYPOSITION | MF_CHECKED); - break; - case 44100: - CheckMenuItem(menu_hSampleRateMenu, 3, MF_BYPOSITION | MF_CHECKED); - break; - case 48000: - CheckMenuItem(menu_hSampleRateMenu, 4, MF_BYPOSITION | MF_CHECKED); - break; - case 96000: - CheckMenuItem(menu_hSampleRateMenu, 5, MF_BYPOSITION | MF_CHECKED); - break; - } - - CheckMenuItem(menu_hLatencyMenu, 0, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hLatencyMenu, 1, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hLatencyMenu, 2, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hLatencyMenu, 3, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hLatencyMenu, 4, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hLatencyMenu, 5, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hLatencyMenu, sound_latency, MF_BYPOSITION | MF_CHECKED); -} - -// ---------------------------------------------------------------------------- -// RefreshRegionsMenu -// ---------------------------------------------------------------------------- -void menu_RefreshRegionsMenu( ) { - CheckMenuItem(menu_hRegionsMenu, 0, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hRegionsMenu, 2, MF_BYPOSITION | MF_UNCHECKED); - CheckMenuItem(menu_hRegionsMenu, 3, MF_BYPOSITION | MF_UNCHECKED); - switch(region_type) { - case REGION_AUTO: - CheckMenuItem(menu_hRegionsMenu, 0, MF_BYPOSITION | MF_CHECKED); - break; - case REGION_NTSC: - CheckMenuItem(menu_hRegionsMenu, 2, MF_BYPOSITION | MF_CHECKED); - break; - case REGION_PAL: - CheckMenuItem(menu_hRegionsMenu, 3, MF_BYPOSITION | MF_CHECKED); - break; - } -} - -// ---------------------------------------------------------------------------- -// RefreshEmulationMenu -// ---------------------------------------------------------------------------- -void menu_RefreshEmulationMenu( ) { - CheckMenuItem(menu_hEmulationMenu, 2, MF_BYPOSITION | ((bios_enabled)? MF_CHECKED: MF_UNCHECKED)); - if(!cartridge_IsLoaded( )) { - EnableMenuItem(menu_hEmulationMenu, 0, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(menu_hEmulationMenu, 2, MF_BYPOSITION | MF_ENABLED); - } - else { - EnableMenuItem(menu_hEmulationMenu, 0, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(menu_hEmulationMenu, 2, MF_BYPOSITION | MF_GRAYED); - } - - CheckMenuItem(menu_hEmulationMenu, 3, MF_BYPOSITION | ((database_enabled)? MF_CHECKED: MF_UNCHECKED)); - for(int index = 0; index < 15; index++) { - CheckMenuItem(menu_hFrameSkipMenu, index, MF_BYPOSITION | MF_UNCHECKED); - } - switch(console_frameSkip) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - CheckMenuItem(menu_hFrameSkipMenu, console_frameSkip, MF_BYPOSITION | MF_CHECKED); - break; - case 15: - CheckMenuItem(menu_hFrameSkipMenu, 11, MF_BYPOSITION | MF_CHECKED); - break; - case 20: - CheckMenuItem(menu_hFrameSkipMenu, 12, MF_BYPOSITION | MF_CHECKED); - break; - case 25: - CheckMenuItem(menu_hFrameSkipMenu, 13, MF_BYPOSITION | MF_CHECKED); - break; - case 30: - CheckMenuItem(menu_hFrameSkipMenu, 14, MF_BYPOSITION | MF_CHECKED); - break; - } -} - -// ---------------------------------------------------------------------------- -// RefreshFileMenu -// ---------------------------------------------------------------------------- -void menu_RefreshFileMenu( ) { - if(cartridge_IsLoaded( )) { - EnableMenuItem(menu_hFileMenu, 1, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(menu_hFileMenu, 4, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(menu_hFileMenu, 5, MF_BYPOSITION | MF_ENABLED); - } - else { - EnableMenuItem(menu_hFileMenu, 1, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(menu_hFileMenu, 4, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(menu_hFileMenu, 5, MF_BYPOSITION | MF_GRAYED); - } -} - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -bool menu_Initialize(HWND hWnd, HINSTANCE hInstance) { - if(hWnd == NULL) { - logger_LogError(IDS_INPUT1,""); - } - if(hInstance == NULL) { - logger_LogError(IDS_INPUT2,""); - return false; - } - - menu_hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_MAIN)); - if(menu_hMenu == NULL) { - logger_LogError(IDS_MENU2,""); - logger_LogError("",common_GetErrorMessage( )); - return false; - } - - if(!SetMenu(hWnd, menu_hMenu)) { - logger_LogError(IDS_MENU3,""); - logger_LogError("",common_GetErrorMessage( )); - return false; - } - - menu_hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR)); - if(menu_hAccel == NULL) { - logger_LogError(IDS_MENU4,""); - logger_LogError("",common_GetErrorMessage( )); - return false; - } - - menu_hFileMenu = GetSubMenu(menu_hMenu, 0); - if(menu_hFileMenu == NULL) { - logger_LogError(IDS_MENU5,""); - return false; - } - - menu_hRecentMenu = GetSubMenu(menu_hFileMenu, 2); - if(menu_hRecentMenu == NULL) { - logger_LogError(IDS_MENU6,""); - return false; - } - - menu_hOptionsMenu = GetSubMenu(menu_hMenu, 1); - if(menu_hOptionsMenu == NULL) { - logger_LogError(IDS_MENU7,""); - return false; - } - - menu_hDisplayMenu = GetSubMenu(menu_hOptionsMenu, 3); - if(menu_hDisplayMenu == NULL) { - logger_LogError(IDS_MENU8,""); - return false; - } - - menu_hScreenshotMenu = GetSubMenu(menu_hDisplayMenu, 10); - if(menu_hScreenshotMenu == NULL) { - logger_LogError(IDS_MENU8,""); - return false; - } - - menu_hModesMenu = GetSubMenu(menu_hDisplayMenu, 1); - if(menu_hModesMenu == NULL) { - logger_LogError(IDS_MENU9,""); - return false; - } - - menu_hSoundMenu = GetSubMenu(menu_hOptionsMenu, 4); - if(menu_hSoundMenu == NULL) { - logger_LogError(IDS_MENU10,""); - return false; - } - - menu_hSampleRateMenu = GetSubMenu(menu_hSoundMenu, 2); - if(menu_hSampleRateMenu == NULL) { - logger_LogError(IDS_MENU11,""); - return false; - } - - menu_hLatencyMenu = GetSubMenu(menu_hSoundMenu, 3); - if(menu_hLatencyMenu == NULL) { - logger_LogError(IDS_MENU11,""); - return false; - } - - menu_hEmulationMenu = GetSubMenu(menu_hOptionsMenu, 5); - if(menu_hEmulationMenu == NULL) { - logger_LogError(IDS_MENU12,""); - return false; - } - - menu_hRegionsMenu = GetSubMenu(menu_hEmulationMenu, 0); - if(menu_hRegionsMenu == NULL) { - logger_LogError(IDS_MENU13,""); - return false; - } - - menu_hFrameSkipMenu = GetSubMenu(menu_hEmulationMenu, 1); - if(menu_hFrameSkipMenu == NULL) { - logger_LogError(IDS_MENU14,""); - return false; - } - - menu_hInputMenu = GetSubMenu(menu_hOptionsMenu, 6); - if(menu_hInputMenu == NULL) { - logger_LogError(IDS_MENU15,""); - return false; - } - - menu_hHelpMenu = GetSubMenu(menu_hMenu, 2); - if(menu_hHelpMenu == NULL) { - logger_LogError(IDS_MENU16,""); - return false; - } - - menu_hWnd = hWnd; - return true; -} - -// ---------------------------------------------------------------------------- -// Refresh -// ---------------------------------------------------------------------------- -void menu_Refresh( ) { - menu_RefreshFileMenu( ); - menu_RefreshDisplayMenu( ); - menu_RefreshModesMenu( ); - menu_RefreshRecentMenu( ); - menu_RefreshOptionsMenu( ); - menu_RefreshSoundMenu( ); - menu_RefreshRegionsMenu( ); - menu_RefreshEmulationMenu( ); -} - -// ---------------------------------------------------------------------------- -// SetEnabled -// ---------------------------------------------------------------------------- -void menu_SetEnabled(bool enabled) { - if(enabled) { - SetMenu(menu_hWnd, menu_hMenu); - } - else { - SetMenu(menu_hWnd, NULL); - } -} - -// ---------------------------------------------------------------------------- -// IsEnabled -// ---------------------------------------------------------------------------- -bool menu_IsEnabled( ) { - return (GetMenu(menu_hWnd) == NULL)? false: true; -} \ No newline at end of file diff --git a/Win/Menu.h b/Win/Menu.h deleted file mode 100755 index 0e63d93..0000000 --- a/Win/Menu.h +++ /dev/null @@ -1,53 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Menu.h -// ---------------------------------------------------------------------------- -#ifndef MENU_H -#define MENU_H -#define NULL 0 - -#include -#include -#include "Resource.h" -#include "Logger.h" -#include "Console.h" -#include "Common.h" -#include "Display.h" -#include "Sound.h" -#include "Database.h" -#include "Bios.h" - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern bool menu_Initialize(HWND hWnd, HINSTANCE hInstance); -extern void menu_Refresh( ); -extern void menu_SetEnabled(bool enabled); -extern bool menu_IsEnabled( ); -extern HACCEL menu_hAccel; -extern bool screenshot1; -extern bool screenshot2; - - -#endif \ No newline at end of file diff --git a/Win/ProSystem.aps b/Win/ProSystem.aps deleted file mode 100755 index 0688234..0000000 Binary files a/Win/ProSystem.aps and /dev/null differ diff --git a/Win/ProSystem.ico b/Win/ProSystem.ico deleted file mode 100755 index e2b354e..0000000 Binary files a/Win/ProSystem.ico and /dev/null differ diff --git a/Win/ProSystem.rc b/Win/ProSystem.rc deleted file mode 100755 index 508510b..0000000 --- a/Win/ProSystem.rc +++ /dev/null @@ -1,560 +0,0 @@ -//Microsoft Developer Studio generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Menu -// - -IDR_MENU_MAIN MENU DISCARDABLE -BEGIN - POPUP "&File" - BEGIN - MENUITEM "&Open...\tCtrl+O", IDM_FILE_OPEN - MENUITEM "&Close", IDM_FILE_CLOSE - POPUP "&Recent" - BEGIN - MENUITEM "&0", IDM_RECENT_SLOT0 - MENUITEM "&1", IDM_RECENT_SLOT1 - MENUITEM "&2", IDM_RECENT_SLOT2 - MENUITEM "&3", IDM_RECENT_SLOT3 - MENUITEM "&4", IDM_RECENT_SLOT4 - MENUITEM "&5", IDM_RECENT_SLOT5 - MENUITEM "&6", IDM_RECENT_SLOT6 - MENUITEM "&7", IDM_RECENT_SLOT7 - MENUITEM "&8", IDM_RECENT_SLOT8 - MENUITEM "&9", IDM_RECENT_SLOT9 - END - MENUITEM SEPARATOR - MENUITEM "Save...\tCtrl+S", IDM_FILE_SAVE - MENUITEM "&Load...\tCtrl+L", IDM_FILE_LOAD - MENUITEM SEPARATOR - MENUITEM "&Exit", IDM_FILE_EXIT - END - POPUP "&Options" - BEGIN - MENUITEM "&Reset\tCtrl+R", IDM_OPTIONS_RESET - MENUITEM "&Pause\tCtrl+P", IDM_OPTIONS_PAUSE - MENUITEM SEPARATOR - POPUP "&Display" - BEGIN - MENUITEM "&Full Screen\tCtrl+F", IDM_DISPLAY_FULLSCREEN - POPUP "&Modes" - BEGIN - MENUITEM " ", IDM_BLANK - END - MENUITEM "&Stretched", IDM_DISPLAY_STRETCHED - MENUITEM "&Palette...", IDM_DISPLAY_PALETTE - MENUITEM SEPARATOR - MENUITEM "x&1", IDM_DISPLAY_ZOOM1 - MENUITEM "x&2", IDM_DISPLAY_ZOOM2 - MENUITEM "x&3", IDM_DISPLAY_ZOOM3 - MENUITEM "x&4", IDM_DISPLAY_ZOOM4 - MENUITEM SEPARATOR - POPUP "S&creenshot...\tF12" - BEGIN - MENUITEM "Remove non-web symbols", ID_OPTIONS_DISPLAY_SCREENSHOT_REMOVENONWEBSYMBOLS - - MENUITEM "Replace spaces by ""_""", ID_OPTIONS_DISPLAY_SCREENSHOT_REPLACESPACESBY - - END - END - POPUP "&Sound" - BEGIN - MENUITEM "&Mute\tCtrl+M", IDM_SOUND_MUTE - MENUITEM SEPARATOR - POPUP "&Sample Rate" - BEGIN - MENUITEM "11025", IDM_SAMPLERATE_11025 - MENUITEM "22050", IDM_SAMPLERATE_22050 - MENUITEM "31440", IDM_SAMPLERATE_31440 - MENUITEM "44100", IDM_SAMPLERATE_44100 - MENUITEM "48000", IDM_SAMPLERATE_48000 - MENUITEM "96000", IDM_SAMPLERATE_96000 - END - POPUP "&Latency" - BEGIN - MENUITEM "&None", IDM_LATENCY_NONE - MENUITEM "&Very Low", IDM_LATENCY_VERYLOW - MENUITEM "&Low", IDM_LATENCY_LOW - MENUITEM "&Medium", IDM_LATENCY_MEDIUM - MENUITEM "&High", IDM_LATENCY_HIGH - MENUITEM "&Very High", IDM_LATENCY_VERYHIGH - END - END - POPUP "&Emulation" - BEGIN - POPUP "&Region" - BEGIN - MENUITEM "&Auto", IDM_REGION_AUTO - MENUITEM SEPARATOR - MENUITEM "&NTSC", IDM_REGION_NTSC - MENUITEM "&PAL", IDM_REGION_PAL - END - POPUP "&Frame Skip" - BEGIN - MENUITEM "0", IDM_FRAMESKIP_0 - MENUITEM "1", IDM_FRAMESKIP_1 - MENUITEM "2", IDM_FRAMESKIP_2 - MENUITEM "3", IDM_FRAMESKIP_3 - MENUITEM "4", IDM_FRAMESKIP_4 - MENUITEM "5", IDM_FRAMESKIP_5 - MENUITEM "6", IDM_FRAMESKIP_6 - MENUITEM "7", IDM_FRAMESKIP_7 - MENUITEM "8", IDM_FRAMESKIP_8 - MENUITEM "9", IDM_FRAMESKIP_9 - MENUITEM "10", IDM_FRAMESKIP_10 - MENUITEM "15", IDM_FRAMESKIP_15 - MENUITEM "20", IDM_FRAMESKIP_20 - MENUITEM "25", IDM_FRAMESKIP_25 - MENUITEM "30", IDM_FRAMESKIP_30 - END - MENUITEM "&BIOS...", IDM_EMULATION_BIOS - MENUITEM "&Database...", IDM_EMULATION_DATABASE - END - POPUP "&Input" - BEGIN - MENUITEM "Controller &1...", IDM_INPUT_CONTROLLER1 - MENUITEM "Controller &2...", IDM_INPUT_CONTROLLER2 - MENUITEM "&Console...", IDM_INPUT_CONSOLE - MENUITEM "&User...", IDM_INPUT_USER - END - MENUITEM SEPARATOR - MENUITEM "&Menu\tEsc", IDM_OPTIONS_MENU - END - POPUP "&Help" - BEGIN - MENUITEM "&Contents...\tF1", IDM_HELP_CONTENTS - MENUITEM SEPARATOR - MENUITEM "&About...", IDM_HELP_ABOUT - END -END - - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE DISCARDABLE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE DISCARDABLE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE DISCARDABLE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Accelerator -// - -IDR_ACCELERATOR ACCELERATORS DISCARDABLE -BEGIN - "F", IDM_DISPLAY_FULLSCREEN, VIRTKEY, CONTROL, NOINVERT - "L", IDM_FILE_LOAD, VIRTKEY, CONTROL, NOINVERT - "M", IDM_SOUND_MUTE, VIRTKEY, CONTROL, NOINVERT - "O", IDM_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT - "P", IDM_OPTIONS_PAUSE, VIRTKEY, CONTROL, NOINVERT - "R", IDM_OPTIONS_RESET, VIRTKEY, CONTROL, NOINVERT - "S", IDM_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT - VK_F1, IDM_HELP_CONTENTS, VIRTKEY, NOINVERT - VK_F12, IDM_DISPLAY_SCREENSHOT, VIRTKEY, NOINVERT -END - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_ICON_PROSYSTEM ICON DISCARDABLE "ProSystem.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_DIALOG_ABOUT DIALOG DISCARDABLE 0, 0, 161, 94 -STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU -CAPTION "About ProSystem" -FONT 8, "MS Sans Serif" -BEGIN - ICON IDI_ICON_PROSYSTEM,IDC_STATIC,5,4,20,20 - CTEXT "ProSystem Emulator",IDC_STATIC,33,6,73,8 - DEFPUSHBUTTON "OK",IDC_BUTTON_ABOUT_OK,60,69,45,14 - CTEXT "Copyright 2005 Greg Stanton",IDC_STATIC,19,33,125,8, - SS_CENTERIMAGE - CTEXT "Atari 7800",IDC_STATIC,35,15,68,8 - CTEXT "",IDC_STATIC_VERSION2,20,59,125,8,SS_CENTERIMAGE - CTEXT "modified by Leonis, 2008",IDC_STATIC_VERSION3,19,43,125, - 8,SS_CENTERIMAGE -END - -IDD_DIALOG_CONTROLLER DIALOG DISCARDABLE 0, 0, 242, 154 -STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU -FONT 8, "MS Sans Serif" -BEGIN - COMBOBOX IDC_COMBO_CONTROLLER_UP,165,24,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - LTEXT "Up",IDC_STATIC,7,26,36,10,SS_CENTERIMAGE - LTEXT "Down",IDC_STATIC,7,41,36,10,SS_CENTERIMAGE - LTEXT "Left",IDC_STATIC,7,56,36,10,SS_CENTERIMAGE - LTEXT "Right",IDC_STATIC,7,71,36,10,SS_CENTERIMAGE - LTEXT "Button 1",IDC_STATIC,7,86,36,10,SS_CENTERIMAGE - LTEXT "Button 2",IDC_STATIC,7,101,36,10,SS_CENTERIMAGE - PUSHBUTTON "OK",IDC_BUTTON_CONTROLLER_OK,80,124,40,14 - COMBOBOX IDC_COMBO_CONTROLLER_DOWN,165,39,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_CONTROLLER_LEFT,165,54,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_CONTROLLER_RIGHT,165,69,57,151, - CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_CONTROLLER_BUTTON1,165,85,57,151, - CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_CONTROLLER_BUTTON2,165,99,57,151, - CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Cancel",IDC_BUTTON_CONTROLLER_CANCEL,122,124,40,14 - COMBOBOX IDC_COMBO_DEVICE_UP,45,24,115,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_DOWN,45,39,115,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_LEFT,45,54,115,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_RIGHT,45,69,115,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_BUTTON1,45,84,115,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_BUTTON2,45,99,115,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - LTEXT "Part / Key",IDC_STATIC,165,13,36,10,SS_CENTERIMAGE - LTEXT "Device",IDC_STATIC,45,13,50,10,SS_CENTERIMAGE -END - -IDD_DIALOG_CONSOLE DIALOG DISCARDABLE 0, 0, 240, 135 -STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU -CAPTION "Console" -FONT 8, "MS Sans Serif" -BEGIN - COMBOBOX IDC_COMBO_CONSOLE_RESET,163,25,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - LTEXT "Reset",-1,7,27,36,10,SS_CENTERIMAGE - LTEXT "Select",-1,7,42,36,10,SS_CENTERIMAGE - LTEXT "Pause",-1,7,57,36,10,SS_CENTERIMAGE - LTEXT "R Difficulty",-1,7,72,36,10,SS_CENTERIMAGE - LTEXT "L Difficulty",-1,7,87,36,10,SS_CENTERIMAGE - PUSHBUTTON "OK",IDC_BUTTON_CONSOLE_OK,79,114,40,14 - COMBOBOX IDC_COMBO_CONSOLE_SELECT,163,39,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_CONSOLE_PAUSE,163,54,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_CONSOLE_RIGHT,163,70,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_CONSOLE_LEFT,163,86,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Cancel",IDC_BUTTON_CONSOLE_CANCEL,121,114,40,14 - COMBOBOX IDC_COMBO_DEVICE_RESET,46,25,110,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_SELECT,46,39,110,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_PAUSE,46,54,110,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_RIGHTD,46,70,110,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_LEFTD,46,86,110,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - LTEXT "Device",-1,45,13,52,10,SS_CENTERIMAGE - LTEXT "Part / Key",-1,165,13,36,10,SS_CENTERIMAGE -END - -IDD_DIALOG_USER DIALOG DISCARDABLE 0, 0, 311, 94 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Dialog" -FONT 8, "MS Sans Serif" -BEGIN - DEFPUSHBUTTON "OK",IDC_BUTTON_USER_OK,105,73,50,14 - PUSHBUTTON "Cancel",IDC_BUTTON_USER_CANCEL,160,73,50,14 - COMBOBOX IDC_COMBO_MOD_MENU,171,27,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - LTEXT "Menu",IDC_STATIC,13,29,36,10,SS_CENTERIMAGE - LTEXT "Exit",IDC_STATIC,13,44,36,10,SS_CENTERIMAGE - COMBOBOX IDC_COMBO_MOD_EXIT,171,42,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_MENU,51,27,115,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_DEVICE_EXIT,51,42,115,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - LTEXT "Modifier",IDC_STATIC,171,16,52,10,SS_CENTERIMAGE - LTEXT "Device",IDC_STATIC,51,16,49,10,SS_CENTERIMAGE - COMBOBOX IDC_COMBO_PART_MENU,237,27,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - COMBOBOX IDC_COMBO_PART_EXIT,237,42,57,151,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - LTEXT "Part / Key",IDC_STATIC,237,16,36,10,SS_CENTERIMAGE -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO DISCARDABLE -BEGIN - IDD_DIALOG_ABOUT, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 154 - TOPMARGIN, 7 - BOTTOMMARGIN, 87 - END - - IDD_DIALOG_CONTROLLER, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 235 - TOPMARGIN, 7 - BOTTOMMARGIN, 147 - END - - IDD_DIALOG_CONSOLE, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 233 - TOPMARGIN, 7 - BOTTOMMARGIN, 128 - END - - IDD_DIALOG_USER, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 304 - TOPMARGIN, 7 - BOTTOMMARGIN, 87 - END -END -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// - -STRINGTABLE DISCARDABLE -BEGIN - IDS_ZIP1 "Zip filename is invalid." - IDS_ZIP2 "It is not a valid zip file:" - IDS_ZIP3 "Failed to find the first file within the zip file." - IDS_ZIP5 "Failed to retrieve the current zipped file info." - IDS_ZIP6 "Data parameter is invalid." - IDS_ZIP8 "Failed to read first file data within the zip file" - IDS_ZIP9 "Filename is invalid." - IDS_ZIP10 "Failed to create the zip file" - IDS_ZIP11 "Failed to open a new file within the zip file" - IDS_ZIP12 "Failed to write data to the zip file" - IDS_BIOS1 "Bios filename is invalid." - IDS_BIOS2 "Opening bios file" - IDS_BIOS3 "Failed to open the bios file" -END - -STRINGTABLE DISCARDABLE -BEGIN - IDS_BIOS4 "Failed to find the end of the bios file." - IDS_BIOS5 "Failed to find the size of the bios file." - IDS_BIOS6 "Failed to read the bios data." - IDS_CARTRIDGE1 "Cartridge data is invalid." - IDS_CARTRIDGE2 "Cartridge filename is invalid." - IDS_CARTRIDGE3 "Failed to open the cartridge file for reading:" - IDS_CARTRIDGE4 "Failed to find the end of the cartridge file." - IDS_CARTRIDGE5 "Failed to find the size of the cartridge file." - IDS_CARTRIDGE6 "Failed to read the cartridge data." - IDS_CARTRIDGE7 "Failed to load the cartridge data into memory." - IDS_PALETTE1 "Palette filename is invalid." - IDS_PALETTE2 "Opening palette file:" - IDS_PALETTE3 "Failed to open the palette file for reading:" - IDS_PALETTE4 "Failed to read the palette data." - IDS_PROSYSTEM1 "Filename is invalid." - IDS_PROSYSTEM2 "Saving game state to file" -END - -STRINGTABLE DISCARDABLE -BEGIN - IDS_SOUND14 "Failed to reset the position of the sound pointer in the sound buffer." - IDS_SOUND15 "Failed to start playing the sound buffer." - IDS_SOUND16 "Failed to stop the sound buffer." - IDS_CARTRIDGE8 "Opening cartridge file" - IDS_CARTRIDGE9 "ProSystem don't want to execute CC2 hacks." -END - -STRINGTABLE DISCARDABLE -BEGIN - IDS_PROSYSTEM3 "Failed to open the file for writing:" - IDS_PROSYSTEM4 "Failed to write the save state data to the file" - IDS_PROSYSTEM5 "Failed to compress the save state data to the file:" - IDS_PROSYSTEM6 "Loading game state from file " - IDS_PROSYSTEM7 "Failed to open the file for reading:" - IDS_PROSYSTEM8 "Failed to find the end of the file." - IDS_PROSYSTEM9 "Failed to find the size of the file." - IDS_PROSYSTEM10 "Save state file has an invalid size." - IDS_PROSYSTEM11 "Failed to read the file data." - IDS_PROSYSTEM12 "Save state file has an invalid size." - IDS_PROSYSTEM13 "File is not a valid ProSystem save state." - IDS_PROSYSTEM14 "Load state digest does not match loaded cartridge digest" - IDS_PROSYSTEM15 "Save state file has an invalid size." - IDS_CONSOLE1 "Failed to save the screenshot to a file." - IDS_CONSOLE2 "Failed to register the window class." - IDS_CONSOLE3 "Failed to initialize the main menu." -END - -STRINGTABLE DISCARDABLE -BEGIN - IDS_CONSOLE4 "Failed to initialize the display." - IDS_CONSOLE5 "Failed to set the display to windowed mode." - IDS_CONSOLE6 "Failed to initialize the sound." - IDS_CONSOLE7 "Failed to save the state to a file." - IDS_DATABASE1 "Accessing database" - IDS_DATABASE2 "Failed to open the database for reading." - IDS_DISPLAY1 "Failed to create the clipper." - IDS_DISPLAY2 "Failed to attach the window handle to the clipper." - IDS_DISPLAY3 "Failed to attach the clipper to the primary surface." - IDS_DISPLAY4 "Failed to restore the primary surface." - IDS_DISPLAY5 "Failed to restore the offscreen surface." - IDS_DISPLAY6 "Direct draw has not been initialized." - IDS_DISPLAY7 "Direct draw primary surface is invalid." - IDS_DISPLAY8 "Direct draw offscreen surface is invalid." - IDS_DISPLAY9 "Direct draw palette is invalid." - IDS_DISPLAY10 "Failed to set the palette entries into the palette." -END - -STRINGTABLE DISCARDABLE -BEGIN - IDS_DISPLAY11 "Failed to retrieve the display mode." - IDS_DISPLAY12 "Window handle is invalid." - IDS_DISPLAY13 "Failed to initialize direct draw." - IDS_DISPLAY14 "Failed to enumerate display modes." - IDS_DISPLAY15 "Failed to set the cooperative level to fullscreen/exclusive." - IDS_DISPLAY16 "Failed to set the display mode to" - IDS_DISPLAY17 "Failed to create the primary surface." - IDS_DISPLAY18 "Failed to create the offscreen surface." - IDS_DISPLAY19 "Failed to set the clipper." - IDS_DISPLAY20 "Failed to create the 8-bit palette." - IDS_DISPLAY21 "Failed to attach the palette to the primary surface." - IDS_DISPLAY22 "Failed to reset the palette." - IDS_DISPLAY23 "Failed to set the cooperative level to normal." - IDS_DISPLAY24 "Failed to create the offscreen surface." - IDS_DISPLAY25 "Failed to lock the offscreen surface." - IDS_DISPLAY26 "Failed to unlock the offscreen surface." -END - -STRINGTABLE DISCARDABLE -BEGIN - IDS_DISPLAY27 "Failed to blit the offscreen surface data to the primary surface." - IDS_DISPLAY28 "Failed to reset the palette for 16 bit per pixel modes." - IDS_DISPLAY29 "Failed to reset the palette for 8 bit per pixel modes." - IDS_DISPLAY30 "Screenshot filename is invalid." - IDS_DISPLAY31 "Failed to open the screenshot file for writing:" - IDS_DISPLAY32 "Failed to perform clear on offscreen surface." - IDS_DISPLAY33 "Failed to perform clear on primary surface." - IDS_INPUT1 "Handle to the window is invalid." - IDS_INPUT2 "Handle to the application instance is invalid." - IDS_INPUT3 "Failed to initialize direct input." - IDS_INPUT4 "Failed to create the keyboard device." - IDS_INPUT5 "Failed to set the keyboard format." - IDS_INPUT6 "Failed to set the cooperative level." - IDS_INPUT7 "Failed to aquire the keyboard." - IDS_INPUT8 "Direct input has not been initialized." - IDS_INPUT9 "Direct input keyboard has not been initialized." -END - -STRINGTABLE DISCARDABLE -BEGIN - IDS_INPUT10 "Keyboard input buffer is invalid." - IDS_INPUT11 "Failed to retrieve the keyboard state." - IDS_INPUT12 "Failed to retrieve the joystick state." - IDS_MENU1 "Failed to load the menu resource." - IDS_MENU2 "Failed to load the menu resource." - IDS_MENU3 "Failed to attach the menu to the console." - IDS_MENU4 "Failed to load the menu accelerator resource." - IDS_MENU5 "Failed to retrieve a handle to the file menu." - IDS_MENU6 "Failed to retrieve a handle to the recent menu." - IDS_MENU7 "Failed to retrieve a handle to the opetions menu." - IDS_MENU8 "Failed to retrieve a handle to the display menu." - IDS_MENU9 "Failed to retrieve a handle to the modes menu." - IDS_MENU10 "Failed to retrieve a handle to the sound menu." - IDS_MENU11 "Failed to retrieve a handle to the latency menu." - IDS_MENU12 "Failed to retrieve a handle to the emulation menu." - IDS_MENU13 "Failed to retrieve a handle to the regions menu." -END - -STRINGTABLE DISCARDABLE -BEGIN - IDS_MENU14 "Failed to retrieve a handle to the frame skip menu." - IDS_MENU15 "Failed to retrieve a handle to the input menu." - IDS_MENU16 "Failed to retrieve a handle to the help menu." - IDS_SOUND1 "Failed to restore the sound buffer." - IDS_SOUND2 "Failed to release the sound buffer." - IDS_SOUND3 "Failed to release direct sound." - IDS_SOUND4 "Failed to initialize direct sound." - IDS_SOUND5 "Failed to create the primary sound buffer." - IDS_SOUND6 "Failed to set the default format." - IDS_SOUND7 "Direct sound has not been initialized." - IDS_SOUND8 "Direct sound primary buffer has not been initialized." - IDS_SOUND9 "Failed to set the primary sound buffer's format." - IDS_SOUND10 "Failed to create the sound buffer." - IDS_SOUND11 "Direct sound buffer has not been initialized." - IDS_SOUND12 "Failed to lock the sound buffer." - IDS_SOUND13 "Failed to unlock the sound buffer." -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/Win/Sound.cpp b/Win/Sound.cpp deleted file mode 100755 index 0f08502..0000000 --- a/Win/Sound.cpp +++ /dev/null @@ -1,433 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Sound.cpp -// ---------------------------------------------------------------------------- -#include "Sound.h" -#define SOUND_LATENCY_SCALE 4 - -byte sound_latency = SOUND_LATENCY_VERY_LOW; - -static const WAVEFORMATEX SOUND_DEFAULT_FORMAT = {WAVE_FORMAT_PCM, 1, 44100, 44100, 1, 8, 0}; -static LPDIRECTSOUND sound_dsound = NULL; -static LPDIRECTSOUNDBUFFER sound_primaryBuffer = NULL; -static LPDIRECTSOUNDBUFFER sound_buffer = NULL; -static WAVEFORMATEX sound_format = SOUND_DEFAULT_FORMAT; -static uint sound_counter = 0; -static bool sound_muted = false; - -// ---------------------------------------------------------------------------- -// GetSampleLength -// ---------------------------------------------------------------------------- -static uint sound_GetSampleLength(uint length, uint unit, uint unitMax) { - uint sampleLength = length / unitMax; - uint sampleRemain = length % unitMax; - if(sampleRemain != 0 && sampleRemain >= unit) { - sampleLength++; - } - return sampleLength; -} - -// ---------------------------------------------------------------------------- -// Resample -// ---------------------------------------------------------------------------- -static void sound_Resample(const byte* source, byte* target, int length) { - int measurement = sound_format.nSamplesPerSec; - int sourceIndex = 0; - int targetIndex = 0; - - while(targetIndex < length) { - if(measurement >= 31440) { - target[targetIndex++] = source[sourceIndex]; - measurement -= 31440; - } - else { - sourceIndex++; - measurement += sound_format.nSamplesPerSec; - } - } -} - -// ---------------------------------------------------------------------------- -// RestoreBuffer -// ---------------------------------------------------------------------------- -static bool sound_RestoreBuffer( ) { - if(sound_buffer != NULL) { - HRESULT hr = sound_buffer->Restore( ); - if(FAILED(hr)) { - logger_LogError(IDS_SOUND1,""); - logger_LogError("",common_Format(hr)); - return false; - } - } - return true; -} - -// ---------------------------------------------------------------------------- -// ReleaseBuffer -// ---------------------------------------------------------------------------- -static bool sound_ReleaseBuffer(LPDIRECTSOUNDBUFFER buffer) { - if(buffer != NULL) { - HRESULT hr = buffer->Release( ); - sound_buffer = NULL; - if(FAILED(hr)) { - logger_LogError(IDS_SOUND2,""); - logger_LogError("",common_Format(hr)); - return false; - } - } - return true; -} - -// ---------------------------------------------------------------------------- -// ReleaseSound -// ---------------------------------------------------------------------------- -static bool sound_ReleaseSound( ) { - if(sound_dsound != NULL) { - HRESULT hr = sound_dsound->Release( ); - sound_dsound = NULL; - if(FAILED(hr)) { - logger_LogError(IDS_SOUND3,""); - logger_LogError("",common_Format(hr)); - return false; - } - } - return true; -} - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -bool sound_Initialize(HWND hWnd) { - if(hWnd == NULL) { - logger_LogError(IDS_INPUT1,""); - return false; - } - - HRESULT hr = DirectSoundCreate(NULL, &sound_dsound, NULL); - if(FAILED(hr) || sound_dsound == NULL) { - logger_LogError(IDS_SOUND4,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = sound_dsound->SetCooperativeLevel(hWnd, DSSCL_PRIORITY); - if(FAILED(hr)) { - logger_LogError(IDS_INPUT6,""); - logger_LogError("",common_Format(hr)); - return false; - } - - DSBUFFERDESC primaryDesc; - primaryDesc.dwReserved = 0; - primaryDesc.dwSize = sizeof(DSBUFFERDESC); - primaryDesc.dwFlags = DSBCAPS_PRIMARYBUFFER; - primaryDesc.dwBufferBytes = 0; - primaryDesc.lpwfxFormat = NULL; - - hr = sound_dsound->CreateSoundBuffer(&primaryDesc, &sound_primaryBuffer, NULL); - if(FAILED(hr) || sound_primaryBuffer == NULL) { - logger_LogError(IDS_SOUND5,""); - logger_LogError("",common_Format(hr)); - return false; - } - - if(!sound_SetFormat(SOUND_DEFAULT_FORMAT)) { - logger_LogError(IDS_SOUND6,""); - return false; - } - -//Leonis -sound_SetSampleRate(samplerate); - return true; -} - -// ---------------------------------------------------------------------------- -// SetFormat -// ---------------------------------------------------------------------------- -bool sound_SetFormat(WAVEFORMATEX format) { - if(sound_dsound == NULL) { - logger_LogError(IDS_SOUND7,""); - return false; - } - if(sound_primaryBuffer == NULL) { - logger_LogError(IDS_SOUND8,""); - return false; - } - - HRESULT hr = sound_primaryBuffer->SetFormat(&format); - if(FAILED(hr)) { - logger_LogError(IDS_SOUND9,""); - logger_LogError("",common_Format(hr)); - return false; - } - - DSBUFFERDESC secondaryDesc; - secondaryDesc.dwReserved = 0; - secondaryDesc.dwSize = sizeof(DSBUFFERDESC); - secondaryDesc.dwFlags = DSBCAPS_GLOBALFOCUS; - secondaryDesc.dwBufferBytes = format.nSamplesPerSec; - secondaryDesc.lpwfxFormat = &format; - - hr = sound_dsound->CreateSoundBuffer(&secondaryDesc, &sound_buffer, NULL); - if(FAILED(hr) || sound_buffer == NULL) { - logger_LogError(IDS_SOUND10,""); - logger_LogError("",common_Format(hr)); - return false; - } - - sound_format = format; - return true; -} - -// ---------------------------------------------------------------------------- -// Store -// ---------------------------------------------------------------------------- -bool sound_Store( ) { - if(sound_dsound == NULL) { - logger_LogError(IDS_SOUND7,""); - return false; - } - if(sound_primaryBuffer == NULL) { - logger_LogError(IDS_SOUND8,""); - return false; - } - if(sound_buffer == NULL) { - logger_LogError(IDS_SOUND11,""); - return false; - } - - byte sample[1920]; - uint length = sound_GetSampleLength(sound_format.nSamplesPerSec, prosystem_frame, prosystem_frequency); - sound_Resample(tia_buffer, sample, length); - - if(cartridge_pokey) { - byte pokeySample[1920]; - sound_Resample(pokey_buffer, pokeySample, length); - for(int index = 0; index < length; index++) { - sample[index] += pokeySample[index]; - sample[index] = sample[index] / 2; - } - } - - DWORD lockCount = 0; - byte* lockStream = NULL; - DWORD wrapCount = 0; - byte* wrapStream = NULL; - - HRESULT hr = sound_buffer->Lock(sound_counter, length, (void**)&lockStream, &lockCount, (void**)&wrapStream, &wrapCount, 0); - if(FAILED(hr) || lockStream == NULL) { - logger_LogError(IDS_SOUND12,""); - logger_LogError("",common_Format(hr)); - if(hr != DSERR_BUFFERLOST || !sound_RestoreBuffer( )) { - return false; - } - } - - uint bufferCounter = 0; - for(uint lockIndex = 0; lockIndex < lockCount; lockIndex++) { - lockStream[lockIndex] = sample[bufferCounter++]; - } - - for(uint wrapIndex = 0; wrapIndex < wrapCount; wrapIndex++) { - wrapStream[wrapIndex] = sample[bufferCounter++]; - } - - hr = sound_buffer->Unlock(lockStream, lockCount, wrapStream, wrapCount); - if(FAILED(hr)) { - logger_LogError(IDS_SOUND13,""); - logger_LogError("",common_Format(hr)); - if(hr != DSERR_BUFFERLOST || !sound_RestoreBuffer( )) { - return false; - } - } - - sound_counter += length; - if(sound_counter >= sound_format.nSamplesPerSec) { - sound_counter -= sound_format.nSamplesPerSec; - } - - return true; -} - -// ---------------------------------------------------------------------------- -// Clear -// ---------------------------------------------------------------------------- -bool sound_Clear( ) { - if(sound_dsound == NULL) { - logger_LogError(IDS_SOUND7,""); - return false; - } - if(sound_primaryBuffer == NULL) { - logger_LogError(IDS_SOUND8,""); - return false; - } - if(sound_buffer == NULL) { - logger_LogError(IDS_SOUND11,""); - return false; - } - - byte* lockStream = NULL; - DWORD lockCount = 0; - HRESULT hr = sound_buffer->Lock(0, sound_format.nSamplesPerSec, (void**)&lockStream, &lockCount, NULL, NULL, DSBLOCK_ENTIREBUFFER); - if(FAILED(hr) || lockStream == NULL) { - logger_LogError(IDS_SOUND12,""); - logger_LogError("",common_Format(hr)); - if(hr != DSERR_BUFFERLOST || !sound_RestoreBuffer( )) { - return false; - } - } - - for(uint lockIndex = 0; lockIndex < lockCount; lockIndex++) { - lockStream[lockIndex] = 0; - } - - hr = sound_buffer->Unlock(lockStream, lockCount, NULL, NULL); - if(FAILED(hr)) { - logger_LogError(IDS_SOUND13,""); - logger_LogError("",common_Format(hr)); - if(hr != DSERR_BUFFERLOST || !sound_RestoreBuffer( )) { - return false; - } - } - - return true; -} - -// ---------------------------------------------------------------------------- -// Play -// ---------------------------------------------------------------------------- -bool sound_Play( ) { - if(sound_dsound == NULL) { - logger_LogError(IDS_SOUND7,""); - return false; - } - if(sound_primaryBuffer == NULL) { - logger_LogError(IDS_SOUND8,""); - return false; - } - if(sound_buffer == NULL) { - logger_LogError(IDS_SOUND11,""); - return false; - } - - if(!sound_muted) { - HRESULT hr = sound_buffer->SetCurrentPosition(0); - if(FAILED(hr)) { - logger_LogError(IDS_SOUND14,""); - logger_LogError("",common_Format(hr)); - return false; - } - - hr = sound_buffer->Play(0, 0, DSBPLAY_LOOPING); - if(FAILED(hr)) { - logger_LogError(IDS_SOUND15,""); - logger_LogError("",common_Format(hr)); - if(hr != DSERR_BUFFERLOST || !sound_RestoreBuffer( )) { - return false; - } - } - sound_counter = (sound_format.nSamplesPerSec / prosystem_frequency) * (sound_latency * SOUND_LATENCY_SCALE); - } - return true; -} - -// ---------------------------------------------------------------------------- -// Stop -// ---------------------------------------------------------------------------- -bool sound_Stop( ) { - if(sound_dsound == NULL) { - logger_LogError(IDS_SOUND7,""); - return false; - } - if(sound_primaryBuffer == NULL) { - logger_LogError(IDS_SOUND8,""); - return false; - } - if(sound_buffer == NULL) { - logger_LogError(IDS_SOUND11,""); - return false; - } - - HRESULT hr = sound_buffer->Stop( ); - if(FAILED(hr)) { - logger_LogError(IDS_SOUND16,""); - logger_LogError("",common_Format(hr)); - if(hr != DSERR_BUFFERLOST || !sound_RestoreBuffer( )) { - return false; - } - } - - return true; -} - -// ---------------------------------------------------------------------------- -// SetSampleRate -// ---------------------------------------------------------------------------- -bool sound_SetSampleRate(uint rate) { - sound_format.nSamplesPerSec = rate; - sound_format.nAvgBytesPerSec = rate; - return sound_SetFormat(sound_format); -} - -// ---------------------------------------------------------------------------- -// GetSampleRate -// ---------------------------------------------------------------------------- -uint sound_GetSampleRate( ) { - return sound_format.nSamplesPerSec; -} - -// ---------------------------------------------------------------------------- -// SetMuted -// ---------------------------------------------------------------------------- -bool sound_SetMuted(bool muted) { - if(sound_muted != muted) { - if(!muted) { - if(!sound_Play( )) { - return false; - } - } - else { - if(!sound_Stop( )) { - return false; - } - } - sound_muted = muted; - } - return true; -} - -// ---------------------------------------------------------------------------- -// IsMuted -// ---------------------------------------------------------------------------- -bool sound_IsMuted( ) { - return sound_muted; -} - -// ---------------------------------------------------------------------------- -// Release -// ---------------------------------------------------------------------------- -void sound_Release( ) { - sound_ReleaseBuffer(sound_buffer); - sound_ReleaseBuffer(sound_primaryBuffer); - sound_ReleaseSound( ); -} \ No newline at end of file diff --git a/Win/Sound.h b/Win/Sound.h deleted file mode 100755 index c45d1c6..0000000 --- a/Win/Sound.h +++ /dev/null @@ -1,60 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Sound.h -// ---------------------------------------------------------------------------- -#ifndef SOUND_H -#define SOUND_H -#define SOUND_LATENCY_NONE 0 -#define SOUND_LATENCY_VERY_LOW 1 -#define SOUND_LATENCY_LOW 2 -#define SOUND_LATENCY_MEDIUM 3 -#define SOUND_LATENCY_HIGH 4 -#define SOUND_LATENCY_VERY_HIGH 5 -#define NULL 0 - -#include -#include "Common.h" -#include "Logger.h" -#include "ProSystem.h" -#include "Configuration.h" -#include "Tia.h" -#include "Pokey.h" - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern bool sound_Initialize(HWND hWnd); -extern bool sound_Store( ); -extern bool sound_Clear( ); -extern bool sound_SetFormat(WAVEFORMATEX format); -extern bool sound_Play( ); -extern bool sound_Stop( ); -extern bool sound_SetSampleRate(uint rate); -extern uint sound_GetSampleRate( ); -extern bool sound_SetMuted(bool muted); -extern bool sound_IsMuted( ); -extern void sound_Release( ); -extern byte sound_latency; - -#endif \ No newline at end of file diff --git a/Win/Timer.cpp b/Win/Timer.cpp deleted file mode 100755 index d029587..0000000 --- a/Win/Timer.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Timer.cpp -// ---------------------------------------------------------------------------- -#include "Timer.h" - -static LONGLONG timer_currentTime; -static LONGLONG timer_nextTime; -static LONGLONG timer_counterFrequency; -static uint timer_frameTime; -static bool timer_usingCounter = false; - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -void timer_Initialize( ) { - timer_usingCounter = (QueryPerformanceFrequency((LARGE_INTEGER*)&timer_counterFrequency))? true: false; - timeBeginPeriod(1); -} - -// ---------------------------------------------------------------------------- -// Reset -// ---------------------------------------------------------------------------- -void timer_Reset( ) { - if(timer_usingCounter) { - QueryPerformanceCounter((LARGE_INTEGER*)&timer_nextTime); - timer_frameTime = timer_counterFrequency / prosystem_frequency; - timer_nextTime += timer_frameTime; - } - else { - timer_frameTime = (1000.0 / (double)prosystem_frequency) * 1000; - timer_currentTime = timeGetTime( ) * 1000; - timer_nextTime = timer_currentTime + timer_frameTime; - } -} - -// ---------------------------------------------------------------------------- -// IsTime -// ---------------------------------------------------------------------------- -bool timer_IsTime( ) { - if(timer_usingCounter) { - QueryPerformanceCounter((LARGE_INTEGER*)&timer_currentTime); - } - else { - timer_currentTime = timeGetTime( ) * 1000; - } - - if(timer_currentTime >= timer_nextTime) { - timer_nextTime += timer_frameTime; - return true; - } - return false; -} diff --git a/Win/Timer.h b/Win/Timer.h deleted file mode 100755 index 9a0663b..0000000 --- a/Win/Timer.h +++ /dev/null @@ -1,37 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Timer.h -// ---------------------------------------------------------------------------- -#ifndef TIMER_H -#define TIMER_H - -#include -#include "ProSystem.h" -#include "Logger.h" -#include "Common.h" - -extern void timer_Initialize( ); -extern void timer_Reset( ); -extern bool timer_IsTime( ); - -#endif \ No newline at end of file diff --git a/Win/resource.h b/Win/resource.h deleted file mode 100755 index a8d5d87..0000000 --- a/Win/resource.h +++ /dev/null @@ -1,270 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by ProSystem.rc -// -#define IDS_ZIP1 1 -#define IDS_ZIP2 2 -#define IDS_ZIP3 3 -#define IDS_ZIP5 5 -#define IDS_ZIP6 6 -#define IDS_ZIP8 8 -#define IDS_ZIP9 9 -#define IDS_ZIP10 10 -#define IDS_ZIP11 11 -#define IDS_ZIP12 12 -#define IDS_BIOS1 13 -#define IDS_BIOS2 14 -#define IDS_BIOS3 15 -#define IDS_BIOS4 16 -#define IDS_BIOS5 17 -#define IDS_BIOS6 18 -#define IDS_CARTRIDGE1 19 -#define IDS_CARTRIDGE2 20 -#define IDS_CARTRIDGE3 21 -#define IDS_CARTRIDGE4 22 -#define IDS_CARTRIDGE5 23 -#define IDS_CARTRIDGE6 24 -#define IDS_CARTRIDGE7 25 -#define IDS_PALETTE1 26 -#define IDS_PALETTE2 27 -#define IDS_PALETTE3 28 -#define IDS_PALETTE4 29 -#define IDS_PROSYSTEM1 30 -#define IDS_PROSYSTEM2 31 -#define IDS_PROSYSTEM3 32 -#define IDS_PROSYSTEM4 33 -#define IDS_PROSYSTEM5 34 -#define IDS_PROSYSTEM6 35 -#define IDS_PROSYSTEM7 36 -#define IDS_PROSYSTEM8 37 -#define IDS_PROSYSTEM9 38 -#define IDS_PROSYSTEM10 39 -#define IDS_PROSYSTEM11 40 -#define IDS_PROSYSTEM12 41 -#define IDS_PROSYSTEM13 42 -#define IDS_PROSYSTEM14 43 -#define IDS_PROSYSTEM15 44 -#define IDS_CONSOLE1 45 -#define IDS_CONSOLE2 46 -#define IDS_CONSOLE3 47 -#define IDS_CONSOLE4 48 -#define IDS_CONSOLE5 49 -#define IDS_CONSOLE6 50 -#define IDS_CONSOLE7 51 -#define IDS_DATABASE1 52 -#define IDS_DATABASE2 53 -#define IDS_DISPLAY1 54 -#define IDS_DISPLAY2 55 -#define IDS_DISPLAY3 56 -#define IDS_DISPLAY4 57 -#define IDS_DISPLAY5 58 -#define IDS_DISPLAY6 59 -#define IDS_DISPLAY7 60 -#define IDS_DISPLAY8 61 -#define IDS_DISPLAY9 62 -#define IDS_DISPLAY10 63 -#define IDS_DISPLAY11 64 -#define IDS_DISPLAY12 65 -#define IDS_DISPLAY13 66 -#define IDS_DISPLAY14 67 -#define IDS_DISPLAY15 68 -#define IDS_DISPLAY16 69 -#define IDS_DISPLAY17 70 -#define IDS_DISPLAY18 71 -#define IDS_DISPLAY19 72 -#define IDS_DISPLAY20 73 -#define IDS_DISPLAY21 74 -#define IDS_DISPLAY22 75 -#define IDS_DISPLAY23 76 -#define IDS_DISPLAY24 77 -#define IDS_DISPLAY25 78 -#define IDS_DISPLAY26 79 -#define IDS_DISPLAY27 80 -#define IDS_DISPLAY28 81 -#define IDS_DISPLAY29 82 -#define IDS_DISPLAY30 83 -#define IDS_DISPLAY31 84 -#define IDS_DISPLAY32 85 -#define IDS_DISPLAY33 86 -#define IDS_INPUT1 87 -#define IDS_INPUT2 88 -#define IDS_INPUT3 89 -#define IDS_INPUT4 90 -#define IDS_INPUT5 91 -#define IDS_INPUT6 92 -#define IDS_INPUT7 93 -#define IDS_INPUT8 94 -#define IDS_INPUT9 95 -#define IDS_INPUT10 96 -#define IDS_INPUT11 97 -#define IDS_INPUT12 98 -#define IDS_MENU1 99 -#define IDS_MENU2 100 -#define IDR_MAINMENU 101 -#define IDD_DIALOG_ABOUT 101 -#define IDR_MENU_MAIN 101 -#define IDS_MENU3 101 -#define IDR_ACCELERATOR 102 -#define IDD_DIALOG_CONTROLLER 102 -#define IDS_MENU4 102 -#define IDD_DIALOG_CONSOLE 103 -#define IDS_MENU5 103 -#define IDS_MENU6 104 -#define IDS_MENU7 105 -#define IDS_MENU8 106 -#define IDS_MENU9 107 -#define IDS_MENU10 108 -#define IDS_MENU11 109 -#define IDS_MENU12 110 -#define IDI_ICON_PROSYSTEM 111 -#define IDS_MENU13 111 -#define IDS_MENU14 112 -#define IDS_MENU15 113 -#define IDD_DIALOG_USER 114 -#define IDS_MENU16 114 -#define IDS_SOUND1 115 -#define IDS_SOUND2 116 -#define IDS_SOUND3 117 -#define IDS_SOUND4 118 -#define IDS_SOUND5 119 -#define IDS_SOUND6 120 -#define IDS_SOUND7 121 -#define IDS_SOUND8 122 -#define IDS_SOUND9 123 -#define IDS_SOUND10 124 -#define IDS_SOUND11 125 -#define IDS_SOUND12 126 -#define IDS_SOUND13 127 -#define IDS_SOUND14 128 -#define IDS_SOUND15 129 -#define IDS_SOUND16 130 -#define IDS_STRING132 132 -#define IDS_CARTRIDGE8 133 -#define IDS_CARTRIDGE9 134 -#define IDC_BUTTON_ABOUT_OK 1170 -#define IDC_BUTTON_CONTROLLER_OK 1175 -#define IDC_COMBO_CONTROLLER_UP 1176 -#define IDC_COMBO_CONTROLLER_DOWN 1177 -#define IDC_COMBO_CONTROLLER_LEFT 1178 -#define IDC_COMBO_PART_MENU 1178 -#define IDC_COMBO_CONTROLLER_RIGHT 1179 -#define IDC_COMBO_PART_EXIT 1179 -#define IDC_COMBO_CONTROLLER_BUTTON1 1180 -#define IDC_COMBO_CONSOLE_RESET 1181 -#define IDC_COMBO_DEVICE_UP 1181 -#define IDC_COMBO_CONSOLE_SELECT 1182 -#define IDC_COMBO_DEVICE_DOWN 1182 -#define IDC_COMBO_CONSOLE_PAUSE 1183 -#define IDC_COMBO_DEVICE_LEFT 1183 -#define IDC_COMBO_CONSOLE_RIGHT 1184 -#define IDC_COMBO_DEVICE_RIGHT 1184 -#define IDC_COMBO_CONSOLE_LEFT 1185 -#define IDC_COMBO_DEVICE_BUTTON1 1185 -#define IDC_COMBO_CONTROLLER_BUTTON2 1186 -#define IDC_BUTTON_CONSOLE_OK 1186 -#define IDC_BUTTON_CONTROLLER_CANCEL 1187 -#define IDC_COMBO_DEVICE_RESET 1187 -#define IDC_BUTTON_CONSOLE_CANCEL 1188 -#define IDC_COMBO_DEVICE_BUTTON2 1188 -#define IDC_COMBO_DEVICE_SELECT 1189 -#define IDC_COMBO_DEVICE_PAUSE 1190 -#define IDC_COMBO_DEVICE_MENU 1190 -#define IDC_STATIC_VERSION2 1190 -#define IDC_COMBO_DEVICE_RIGHTD 1191 -#define IDC_COMBO_DEVICE_EXIT 1191 -#define IDC_STATIC_VERSION3 1191 -#define IDC_COMBO_DEVICE_LEFTD 1192 -#define IDC_COMBO_MOD_MENU 1192 -#define IDC_COMBO_MOD_EXIT 1193 -#define IDC_BUTTON_USER_OK 1194 -#define IDC_BUTTON_USER_CANCEL 1195 -#define IDM_RECENT_SLOT0 30000 -#define IDM_RECENT_SLOT1 30001 -#define IDM_RECENT_SLOT2 30002 -#define IDM_RECENT_SLOT3 30003 -#define IDM_RECENT_SLOT4 30004 -#define IDM_RECENT_SLOT5 30005 -#define IDM_RECENT_SLOT6 30006 -#define IDM_RECENT_SLOT7 30007 -#define IDM_RECENT_SLOT8 30008 -#define IDM_RECENT_SLOT9 30009 -#define IDM_FILE_OPEN 40001 -#define IDM_FILE_CLOSE 40007 -#define IDM_SAVE_SAVEAS 40008 -#define IDM_LOAD_LOADFROM 40015 -#define IDM_FILE_EXIT 40021 -#define IDM_OPTIONS_RESET 40022 -#define IDM_OPTIONS_PAUSE 40023 -#define IDM_DISPLAY_FULLSCREEN 40024 -#define IDM_DISPLAY_ZOOM1 40025 -#define IDM_DISPLAY_ZOOM2 40026 -#define IDM_DISPLAY_ZOOM3 40027 -#define IDM_DISPLAY_ZOOM4 40028 -#define IDM_OPTIONS_MENU 40039 -#define IDM_HELP_ABOUT 40040 -#define IDM_OPTIONS_SETTINGS 40062 -#define IDM_SAVE_NEXT 40094 -#define IDM_DISPLAY_SCREENSHOT 40099 -#define IDM_DISPLAY_STRETCHED 40101 -#define IDM_SAMPLERATE_11025 40107 -#define IDM_SAMPLERATE_22050 40108 -#define IDM_SAMPLERATE_31440 40109 -#define IDM_SAMPLERATE_44100 40110 -#define IDM_SAMPLERATE_48000 40111 -#define IDM_SAMPLERATE_96000 40112 -#define IDM_LATENCY_NONE 40113 -#define IDM_LATENCY_VERYLOW 40114 -#define IDM_LATENCY_LOW 40115 -#define IDM_LATENCY_MEDIUM 40116 -#define IDM_LATENCY_HIGH 40117 -#define IDM_LATENCY_VERYHIGH 40118 -#define IDM_BLANK 40144 -#define IDM_FRAMESKIP_0 40146 -#define IDM_FRAMESKIP_1 40148 -#define IDM_FRAMESKIP_5 40160 -#define IDM_FRAMESKIP_10 40161 -#define IDM_FRAMESKIP_15 40162 -#define IDM_FRAMESKIP_20 40163 -#define IDM_FRAMESKIP_25 40164 -#define IDM_FRAMESKIP_30 40165 -#define IDM_FILE_SAVE 40167 -#define IDM_FILE_LOAD 40168 -#define IDM_DISPLAY_PALETTE 40169 -#define IDM_MUTE_TIA 40172 -#define IDM_SOUND_POKEY 40173 -#define IDM_MUTE_ALL 40174 -#define IDM_EMULATION_BIOS 40175 -#define IDM_OPTIONS_INPUT 40176 -#define IDM_REGION_AUTO 40177 -#define IDM_REGION_NTSC 40178 -#define IDM_REGION_PAL 40179 -#define IDM_FRAMESKIP_2 40181 -#define IDM_FRAMESKIP_3 40182 -#define IDM_FRAMESKIP_4 40183 -#define IDM_FRAMESKIP_6 40184 -#define IDM_FRAMESKIP_7 40185 -#define IDM_FRAMESKIP_8 40186 -#define IDM_FRAMESKIP_9 40187 -#define IDM_EMULATION_DATABASE 40189 -#define IDM_SOUND_MUTE 40190 -#define IDM_INPUT_CONTROLLER1 40191 -#define IDM_INPUT_CONTROLLER2 40192 -#define IDM_INPUT_CONSOLE 40193 -#define IDM_HELP_CONTENTS 40195 -#define IDM_HELP_INDEX 40196 -#define IDM_INPUT_USER 40198 -#define ID_OPTIONS_DISPLAY_SCREENSHOT_REMOVENONWEBSYMBOLS 40200 -#define ID_OPTIONS_DISPLAY_SCREENSHOT_REPLACESPACESBY 40201 -#define IDM_MODES_BASE 50000 -#define IDM_MODES_LAST 51000 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 117 -#define _APS_NEXT_COMMAND_VALUE 40202 -#define _APS_NEXT_CONTROL_VALUE 1196 -#define _APS_NEXT_SYMED_VALUE 119 -#endif -#endif diff --git a/core/Archive.cpp b/core/Archive.cpp deleted file mode 100755 index de25919..0000000 --- a/core/Archive.cpp +++ /dev/null @@ -1,162 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Archive.cpp -// ---------------------------------------------------------------------------- -#include "Archive.h" -#define ARCHIVE_SOURCE "Archive.cpp" - -#define _MAX_PATH 128 - -// ---------------------------------------------------------------------------- -// GetUncompressedFileSize -// ---------------------------------------------------------------------------- -uint archive_GetUncompressedFileSize(std::string filename) { - if(filename.empty( ) || filename.size( ) == 0) { - logger_LogError("Zip filename is invalid.", ARCHIVE_SOURCE); - return 0; - } - - unzFile file = unzOpen(filename.c_str( )); - if(file == NULL) { - logger_LogInfo("Filename " + filename + " is not a valid zip file.", ARCHIVE_SOURCE); - return 0; - } - - int result = unzGoToFirstFile(file); - if(result != UNZ_OK) { - logger_LogInfo("Failed to find the first file within the zip file.", ARCHIVE_SOURCE); - logger_LogInfo("Result: " + result, ARCHIVE_SOURCE); - unzClose(file); - return 0; - } - - unz_file_info_s zipInfo = {0}; - char buffer[_MAX_PATH] = {0}; - result = unzGetCurrentFileInfo(file, &zipInfo, buffer, _MAX_PATH, NULL, 0, NULL, 0); - if(result != UNZ_OK) { - logger_LogInfo("Failed to retrieve the current zipped file info.", ARCHIVE_SOURCE); - logger_LogInfo("Result: " + result, ARCHIVE_SOURCE); - unzClose(file); - return 0; - } - - uint size = zipInfo.uncompressed_size; - unzClose(file); - return size; -} - -// ---------------------------------------------------------------------------- -// Uncompress -// ---------------------------------------------------------------------------- -bool archive_Uncompress(std::string filename, byte* data, uint size) { - if(filename.empty( ) || filename.size( ) == 0) { - logger_LogError("Zip filename is invalid.", ARCHIVE_SOURCE); - return false; - } - if(data == NULL) { - logger_LogError("Data parameter is invalid.", ARCHIVE_SOURCE); - return false; - } - - unzFile file = unzOpen(filename.c_str( )); - if(file == NULL) { - logger_LogInfo("Filename " + filename + " is not a valid zip file.", ARCHIVE_SOURCE); - return false; - } - - int result = unzGoToFirstFile(file); - if(result != UNZ_OK) { - logger_LogInfo("Failed to find the first file within the zip file " + filename + ".", ARCHIVE_SOURCE); - logger_LogInfo("Result: " + result, ARCHIVE_SOURCE); - unzClose(file); - return false; - } - - result = unzOpenCurrentFile(file); - if(result != UNZ_OK) { - logger_LogInfo("Failed to open the first file within the zip file " + filename + ".", ARCHIVE_SOURCE); - logger_LogInfo("Result: " + result, ARCHIVE_SOURCE); - unzClose(file); - return false; - } - - result = unzReadCurrentFile(file, data, size); - if(result != size) { - logger_LogInfo("Failed to read first file data within the zip file " + filename + ".", ARCHIVE_SOURCE); - logger_LogInfo("Result: " + result, ARCHIVE_SOURCE); - unzCloseCurrentFile(file); - unzClose(file); - return false; - } - - unzCloseCurrentFile(file); - unzClose(file); - return true; -} - -// ---------------------------------------------------------------------------- -// Compress -// ---------------------------------------------------------------------------- -bool archive_Compress(std::string zipFilename, std::string filename, const byte* data, uint size) { - if(zipFilename.empty( ) || zipFilename.size( ) == 0) { - logger_LogError("Zip filename is invalid.", ARCHIVE_SOURCE); - return false; - } - if(filename.empty( ) || filename.size( ) == 0) { - logger_LogError("Filename is invalid.", ARCHIVE_SOURCE); - return false; - } - if(data == NULL) { - logger_LogError("Data parameter is invalid.", ARCHIVE_SOURCE); - return false; - } - - zipFile file = zipOpen(zipFilename.c_str( ), APPEND_STATUS_CREATE); - if(file == NULL) { - logger_LogInfo("Failed to create the zip file " + zipFilename + ".", ARCHIVE_SOURCE); - return false; - } - - zip_fileinfo fileInfo = {0}; - fileInfo.dosDate = 1; - - int result = zipOpenNewFileInZip(file, filename.c_str( ), &fileInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_BEST_COMPRESSION); - if(result != ZIP_OK) { - logger_LogInfo("Failed to open a new file within the zip file " + filename + ".", ARCHIVE_SOURCE); - logger_LogInfo("Result: " + result, ARCHIVE_SOURCE); - zipClose(file, "Failed to compress."); - return false; - } - - result = zipWriteInFileInZip(file, data, size); - if(result != ZIP_OK) { - logger_LogInfo("Failed to write data to the zip file " + filename + ".", ARCHIVE_SOURCE); - zipCloseFileInZip(file); - zipClose(file, "Failed to compress."); - return false; - } - - zipCloseFileInZip(file); - zipClose(file, "Comment"); - return true; -} diff --git a/core/Archive.h b/core/Archive.h deleted file mode 100755 index 9482702..0000000 --- a/core/Archive.h +++ /dev/null @@ -1,42 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Archive.h -// ---------------------------------------------------------------------------- -#ifndef ARCHIVE_H -#define ARCHIVE_H - -#include -#include "Logger.h" -#include "Cartridge.h" -#include "zip.h" -#include "unzip.h" - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern uint archive_GetUncompressedFileSize(std::string filename); -extern bool archive_Uncompress(std::string filename, byte* data, uint size); -extern bool archive_Compress(std::string zipFilename, std::string filename, const byte* data, uint size); - -#endif \ No newline at end of file diff --git a/core/Bios.cpp b/core/Bios.cpp deleted file mode 100755 index a752564..0000000 --- a/core/Bios.cpp +++ /dev/null @@ -1,113 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Bios.cpp -// ---------------------------------------------------------------------------- -#include "Bios.h" -#define BIOS_SOURCE "Bios.cpp" - -bool bios_enabled = false; -std::string bios_filename; - -static byte* bios_data = NULL; -static word bios_size = 0; - -// ---------------------------------------------------------------------------- -// Load -// ---------------------------------------------------------------------------- -bool bios_Load(std::string filename) { - if(filename.empty( ) || filename.length( ) == 0) { - logger_LogError("Bios filename is invalid.", BIOS_SOURCE); - return false; - } - - bios_Release( ); - logger_LogInfo("Opening bios file " + filename + ".", BIOS_SOURCE); - - bios_size = archive_GetUncompressedFileSize(filename); - if(bios_size == 0) { - FILE* file = fopen(filename.c_str( ), "rb"); - if(file == NULL) { -#ifndef WII - logger_LogError("Failed to open the bios file " + filename + " for reading.", BIOS_SOURCE); -#endif - return false; - } - - if(fseek(file, 0L, SEEK_END)) { - fclose(file); - logger_LogError("Failed to find the end of the bios file.", BIOS_SOURCE); - return false; - } - - bios_size = ftell(file); - if(fseek(file, 0L, SEEK_SET)) { - fclose(file); - logger_LogError("Failed to find the size of the bios file.", BIOS_SOURCE); - return false; - } - - bios_data = new byte[bios_size]; - if(fread(bios_data, 1, bios_size, file) != bios_size && ferror(file)) { - fclose(file); - logger_LogError("Failed to read the bios data.", BIOS_SOURCE); - bios_Release( ); - return false; - } - - fclose(file); - } - else { - bios_data = new byte[bios_size]; - archive_Uncompress(filename, bios_data, bios_size); - } - - bios_filename = filename; - return true; -} - -// ---------------------------------------------------------------------------- -// IsLoaded -// ---------------------------------------------------------------------------- -bool bios_IsLoaded( ) { - return (bios_data != NULL)? true: false; -} - -// ---------------------------------------------------------------------------- -// Release -// ---------------------------------------------------------------------------- -void bios_Release( ) { - if(bios_data) { - delete [ ] bios_data; - bios_size = 0; - bios_data = NULL; - } -} - -// ---------------------------------------------------------------------------- -// Store -// ---------------------------------------------------------------------------- -void bios_Store( ) { - if(bios_data != NULL && bios_enabled) { - memory_WriteROM(65536 - bios_size, bios_size, bios_data); - } -} diff --git a/core/Cartridge.cpp b/core/Cartridge.cpp deleted file mode 100755 index 766a2c3..0000000 --- a/core/Cartridge.cpp +++ /dev/null @@ -1,505 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Cartridge.cpp -// ---------------------------------------------------------------------------- -#include "Cartridge.h" -#include "Region.h" - -#include -#define CARTRIDGE_SOURCE "Cartridge.cpp" - -std::string cartridge_title; -std::string cartridge_description; -std::string cartridge_year; -std::string cartridge_maker; -std::string cartridge_digest; -std::string cartridge_filename; -byte cartridge_type; -byte cartridge_region; -bool cartridge_pokey; -bool cartridge_pokey450; -byte cartridge_controller[2] = {1, 1}; -byte cartridge_bank; -uint cartridge_flags; -int cartridge_crosshair_x; -int cartridge_crosshair_y; -bool cartridge_dualanalog = false; -bool cartridge_xm = false; -bool cartridge_disable_bios = false; -uint cartridge_hblank = 34; -byte cartridge_left_switch = 1; -byte cartridge_right_switch = 0; -bool cartridge_swap_buttons = false; -bool cartridge_hsc_enabled = false; - -static byte* cartridge_buffer = NULL; -static uint cartridge_size = 0; - -// ---------------------------------------------------------------------------- -// HasHeader -// ---------------------------------------------------------------------------- -static bool cartridge_HasHeader(const byte* header) { - const char HEADER_ID[ ] = {"ATARI7800"}; - for(int index = 0; index < 9; index++) { - if(HEADER_ID[index] != header[index + 1]) { - return false; - } - } - return true; -} - -// ---------------------------------------------------------------------------- -// Header for CC2 hack -// ---------------------------------------------------------------------------- -static bool cartridge_CC2(const byte* header) { - const char HEADER_ID[ ] = {">>"}; - for(int index = 0; index < 2; index++) { - if(HEADER_ID[index] != header[index+1]) { - return false; - } - } - return true; -} - -// ---------------------------------------------------------------------------- -// GetBank -// ---------------------------------------------------------------------------- -static uint cartridge_GetBank(byte bank) { - if ((cartridge_type == CARTRIDGE_TYPE_SUPERCART || cartridge_type == CARTRIDGE_TYPE_SUPERCART_ROM || cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM) && cartridge_size <= 65536) { - // for some of these carts, there are only 4 banks. in this case we ignore bit 3 - // previously, games of this type had to be doubled. The first 4 banks needed to be duplicated at the end of the ROM - return (bank & 3); - } - - return bank; -} - -// ---------------------------------------------------------------------------- -// GetBankOffset -// ---------------------------------------------------------------------------- -static uint cartridge_GetBankOffset(byte bank) { - return cartridge_GetBank(bank) * 16384; -} - -// ---------------------------------------------------------------------------- -// WriteBank -// ---------------------------------------------------------------------------- -static void cartridge_WriteBank(word address, byte bank) { - uint offset = cartridge_GetBankOffset(bank); - if(offset < cartridge_size) { - memory_WriteROM(address, 16384, cartridge_buffer + offset); - cartridge_bank = bank; - } -} - -static void cartridge_SetTypeBySize(uint size) { - if (size <= 0x10000) { - cartridge_type = CARTRIDGE_TYPE_NORMAL; - } else if (size == 0x24000 ) { - cartridge_type = CARTRIDGE_TYPE_SUPERCART_LARGE; - } else if (size == 0x20000 ) { - cartridge_type = CARTRIDGE_TYPE_SUPERCART_ROM; - } else { - cartridge_type = CARTRIDGE_TYPE_SUPERCART; - } -} - -// ---------------------------------------------------------------------------- -// ReadHeader -// ---------------------------------------------------------------------------- -static void cartridge_ReadHeader(const byte* header) { - - char temp[33] = {0}; - for(int index = 0; index < 32; index++) { - temp[index] = header[index + 17]; - } - cartridge_title = temp; - - cartridge_size = header[49] << 24; - cartridge_size |= header[50] << 16; - cartridge_size |= header[51] << 8; - cartridge_size |= header[52]; - - if(header[53] == 0) { - if(cartridge_size > 131072) { - cartridge_type = CARTRIDGE_TYPE_SUPERCART_LARGE; - } - else if(header[54] == 2 || header[54] == 3) { - cartridge_type = CARTRIDGE_TYPE_SUPERCART; - } - else if(header[54] == 4 || header[54] == 5 || header[54] == 6 || header[54] == 7) { - cartridge_type = CARTRIDGE_TYPE_SUPERCART_RAM; - } - else if(header[54] == 8 || header[54] == 9 || header[54] == 10 || header[54] == 11) { - cartridge_type = CARTRIDGE_TYPE_SUPERCART_ROM; - } - else { - cartridge_type = CARTRIDGE_TYPE_NORMAL; - } - } - else { - if(header[53] == 2 /*1*/) { // Wii: Abs and Act were swapped - cartridge_type = CARTRIDGE_TYPE_ABSOLUTE; - } - else if(header[53] == 1 /*2*/) { // Wii: Abs and Act were swapped - cartridge_type = CARTRIDGE_TYPE_ACTIVISION; - } - else { - cartridge_type = CARTRIDGE_TYPE_NORMAL; - } - } - - cartridge_pokey = (header[54] & 1)? true: false; - cartridge_pokey450 = (header[54] & 0x40)? true : false; - if (cartridge_pokey450) { - cartridge_pokey = true; - } - cartridge_controller[0] = header[55]; - cartridge_controller[1] = header[56]; - cartridge_region = header[57]; - cartridge_flags = 0; - cartridge_xm = (header[63] & 1)? true: false; - cartridge_hsc_enabled = header[58]&0x01; - - // Wii: Updates to header interpretation - byte ct1 = header[54]; - if(header[53] == 0) { - if ((ct1&0x0a)==0x0a) { // BIT1 and BIT3 (Supercart Large: 2) rom at $4000 - cartridge_type = CARTRIDGE_TYPE_SUPERCART_LARGE; - } else if ((ct1&0x12)==0x12) { // BIT1 and BIT4 (Supercart ROM: 4) bank6 at $4000 - cartridge_type = CARTRIDGE_TYPE_SUPERCART_ROM; - } else if ((ct1&0x06)==0x06) { // BIT1 and BIT2 (Supercart RAM: 3) ram at $4000 - cartridge_type = CARTRIDGE_TYPE_SUPERCART_RAM; - } else if ((ct1&0x02)==0x02) { // BIT1 (Supercart) bank switched - cartridge_type = CARTRIDGE_TYPE_SUPERCART; - } else if (cartridge_size <= 0x10000 && ((ct1&0x04)==0x04)) { // Size < 64k && BIT2 (Normal RAM: ?) ram at $4000 ) - cartridge_type = CARTRIDGE_TYPE_NORMAL_RAM; - } else { - // Attempt to determine the cartridge type based on its size - cartridge_SetTypeBySize(cartridge_size); - } - } -} - -// ---------------------------------------------------------------------------- -// Load -// ---------------------------------------------------------------------------- -static bool cartridge_Load(const byte* data, uint size) { - if(size <= 128) { - logger_LogError("Cartridge data is invalid.", CARTRIDGE_SOURCE); - return false; - } - - cartridge_Release( ); - - byte header[128] = {0}; - for(int index = 0; index < 128; index++) { - header[index] = data[index]; - } - -if (cartridge_CC2(header)) { - logger_LogError("Prosystem doesn't support CC2 hacks.", CARTRIDGE_SOURCE); - return false; - } - - uint offset = 0; - if(cartridge_HasHeader(header)) { - cartridge_ReadHeader(header); - size -= 128; - offset = 128; - - // Several cartridge headers do not have the proper size. So attempt to use the size - // of the file. - if (cartridge_size != size) { - // Necessary for the following roms: - // Impossible Mission hacks w/ C64 style graphics - if (size % 1024 == 0) { - cartridge_size = size; - } - } - } - else { - cartridge_size = size; - // Attempt to guess the cartridge type based on its size - cartridge_SetTypeBySize(size); - } - - cartridge_buffer = new byte[cartridge_size]; - for(int index = 0; index < cartridge_size; index++) { - cartridge_buffer[index] = data[index + offset]; - } - - cartridge_digest = hash_Compute(cartridge_buffer, cartridge_size); - return true; -} - -// ---------------------------------------------------------------------------- -// Load -// ---------------------------------------------------------------------------- -bool cartridge_Load(std::string filename) { - if(filename.empty( ) || filename.length( ) == 0) { - logger_LogError("Cartridge filename is invalid.", CARTRIDGE_SOURCE); - return false; - } - - cartridge_Release( ); - logger_LogInfo("Opening cartridge file " + filename + ".", CARTRIDGE_SOURCE); - - byte* data = NULL; - //uint size = archive_GetUncompressedFileSize(filename); - uint size = 0; - - if(size == 0) { - FILE *file = fopen(filename.c_str( ), "rb"); - if(file == NULL) { - logger_LogError("Failed to open the cartridge file " + filename + " for reading.", CARTRIDGE_SOURCE); - return false; - } - - if(fseek(file, 0L, SEEK_END)) { - fclose(file); - logger_LogError("Failed to find the end of the cartridge file.", CARTRIDGE_SOURCE); - return false; - } - size = ftell(file); - if(fseek(file, 0L, SEEK_SET)) { - fclose(file); - logger_LogError("Failed to find the size of the cartridge file.", CARTRIDGE_SOURCE); - return false; - } - - data = new byte[size]; - if(fread(data, 1, size, file) != size && ferror(file)) { - fclose(file); - logger_LogError("Failed to read the cartridge data.", CARTRIDGE_SOURCE); - cartridge_Release( ); - delete [ ] data; - return false; - } - - fclose(file); - } - else { - data = new byte[size]; - //archive_Uncompress(filename, data, size); - } - - if(!cartridge_Load(data, size)) { - logger_LogError("Failed to load the cartridge data into memory.", CARTRIDGE_SOURCE); - delete [ ] data; - return false; - } - if(data != NULL) { - delete [ ] data; - } - - cartridge_filename = filename; - return true; -} - -// ---------------------------------------------------------------------------- -// Store -// ---------------------------------------------------------------------------- -void cartridge_Store( ) { - switch(cartridge_type) { - case CARTRIDGE_TYPE_NORMAL: - memory_WriteROM(65536 - cartridge_size, cartridge_size, cartridge_buffer); - break; - case CARTRIDGE_TYPE_NORMAL_RAM: - memory_WriteROM(65536 - cartridge_size, cartridge_size, cartridge_buffer); - memory_ClearROM(16384, 16384); - break; - case CARTRIDGE_TYPE_SUPERCART: { - uint offset = cartridge_size - 16384; - if(offset < cartridge_size) { - memory_WriteROM(49152, 16384, cartridge_buffer + offset); - } - } break; - case CARTRIDGE_TYPE_SUPERCART_LARGE: { - uint offset = cartridge_size - 16384; - if(offset < cartridge_size) { - memory_WriteROM(49152, 16384, cartridge_buffer + offset); - memory_WriteROM(16384, 16384, cartridge_buffer + cartridge_GetBankOffset(0)); - } - } break; - case CARTRIDGE_TYPE_SUPERCART_RAM: { - uint offset = cartridge_size - 16384; - if(offset < cartridge_size) { - memory_WriteROM(49152, 16384, cartridge_buffer + offset); - memory_ClearROM(16384, 16384); - } - } break; - case CARTRIDGE_TYPE_SUPERCART_ROM: { - uint offset = cartridge_size - 16384; - if(offset < cartridge_size && cartridge_GetBankOffset(6) < cartridge_size) { - memory_WriteROM(49152, 16384, cartridge_buffer + offset); - memory_WriteROM(16384, 16384, cartridge_buffer + cartridge_GetBankOffset(6)); - } - } break; - case CARTRIDGE_TYPE_ABSOLUTE: - memory_WriteROM(16384, 16384, cartridge_buffer); - memory_WriteROM(32768, 32768, cartridge_buffer + cartridge_GetBankOffset(2)); - break; - case CARTRIDGE_TYPE_ACTIVISION: - if(122880 < cartridge_size) { - memory_WriteROM(40960, 16384, cartridge_buffer); - memory_WriteROM(16384, 8192, cartridge_buffer + 106496); - memory_WriteROM(24576, 8192, cartridge_buffer + 98304); - memory_WriteROM(32768, 8192, cartridge_buffer + 122880); - memory_WriteROM(57344, 8192, cartridge_buffer + 114688); - } - break; - } -} - -// ---------------------------------------------------------------------------- -// Write -// ---------------------------------------------------------------------------- -void cartridge_Write(word address, byte data) { - switch(cartridge_type) { - case CARTRIDGE_TYPE_SUPERCART: - case CARTRIDGE_TYPE_SUPERCART_RAM: - case CARTRIDGE_TYPE_SUPERCART_ROM: { - uint maxbank = cartridge_size / 16384; - if(address >= 32768 && address < 49152 && cartridge_GetBank(data) < maxbank /*9*/) { - cartridge_StoreBank(data); - } - } break; - case CARTRIDGE_TYPE_SUPERCART_LARGE: { - uint maxbank = cartridge_size / 16384; - if(address >= 32768 && address < 49152 && cartridge_GetBank(data) < maxbank /*9*/) { - cartridge_StoreBank(data + 1); - } - } break; - case CARTRIDGE_TYPE_ABSOLUTE: - if(address == 32768 && (data == 1 || data == 2)) { - cartridge_StoreBank(data - 1); - } - break; - case CARTRIDGE_TYPE_ACTIVISION: - if(address >= 65408) { - cartridge_StoreBank(address & 7); - } - break; - } - -#if 0 // WIi: Moved to Memory.cpp - if(cartridge_pokey && address >= 0x4000 && address <= 0x400f) { - switch(address) { - case POKEY_AUDF1: - pokey_SetRegister(POKEY_AUDF1, data); - break; - case POKEY_AUDC1: - pokey_SetRegister(POKEY_AUDC1, data); - break; - case POKEY_AUDF2: - pokey_SetRegister(POKEY_AUDF2, data); - break; - case POKEY_AUDC2: - pokey_SetRegister(POKEY_AUDC2, data); - break; - case POKEY_AUDF3: - pokey_SetRegister(POKEY_AUDF3, data); - break; - case POKEY_AUDC3: - pokey_SetRegister(POKEY_AUDC3, data); - break; - case POKEY_AUDF4: - pokey_SetRegister(POKEY_AUDF4, data); - break; - case POKEY_AUDC4: - pokey_SetRegister(POKEY_AUDC4, data); - break; - case POKEY_AUDCTL: - pokey_SetRegister(POKEY_AUDCTL, data); - break; - case POKEY_SKCTLS: - pokey_SetRegister(POKEY_SKCTLS, data); - break; - } - } -#endif -} - -// ---------------------------------------------------------------------------- -// StoreBank -// ---------------------------------------------------------------------------- -void cartridge_StoreBank(byte bank) { - switch(cartridge_type) { - case CARTRIDGE_TYPE_SUPERCART: - cartridge_WriteBank(32768, bank); - break; - case CARTRIDGE_TYPE_SUPERCART_RAM: - cartridge_WriteBank(32768, bank); - break; - case CARTRIDGE_TYPE_SUPERCART_ROM: - cartridge_WriteBank(32768, bank); - break; - case CARTRIDGE_TYPE_SUPERCART_LARGE: - cartridge_WriteBank(32768, bank); - break; - case CARTRIDGE_TYPE_ABSOLUTE: - cartridge_WriteBank(16384, bank); - break; - case CARTRIDGE_TYPE_ACTIVISION: - cartridge_WriteBank(40960, bank); - break; - } -} - -// ---------------------------------------------------------------------------- -// IsLoaded -// ---------------------------------------------------------------------------- -bool cartridge_IsLoaded( ) { - return (cartridge_buffer != NULL)? true: false; -} - -// ---------------------------------------------------------------------------- -// Release -// ---------------------------------------------------------------------------- -void cartridge_Release( ) { - if(cartridge_buffer != NULL) { - delete [ ] cartridge_buffer; - cartridge_size = 0; - cartridge_buffer = NULL; - cartridge_title = ""; - cartridge_type = 0; - cartridge_region = 0; - cartridge_pokey = 0; - cartridge_pokey450 = 0; - cartridge_xm = false; - // Default to joysticks - memset( cartridge_controller, 1, sizeof( cartridge_controller ) ); - cartridge_bank = 0; - cartridge_flags = 0; - cartridge_disable_bios = false; - cartridge_crosshair_x = 0; - cartridge_crosshair_y = 0; - cartridge_hblank = HBLANK_DEFAULT; - cartridge_dualanalog = false; - cartridge_left_switch = 1; - cartridge_right_switch = 0; - cartridge_swap_buttons = false; - cartridge_hsc_enabled = false; - } -} diff --git a/core/Common.cpp b/core/Common.cpp deleted file mode 100755 index fae953f..0000000 --- a/core/Common.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Common.cpp -// ---------------------------------------------------------------------------- -#include "Common.h" - -std::string common_defaultPath; - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(double value) { - return common_Format(value, "%f"); -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(double value, std::string specification) { - char buffer[17] = {0}; - sprintf(buffer, specification.c_str( ), value); - return std::string(buffer); -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(uint value) { - char buffer[11] = {0}; - sprintf(buffer, "%d", value); - return std::string(buffer); -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(word value) { - char buffer[6] = {0}; - sprintf(buffer, "%d", value); - return std::string(buffer); -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(byte value) { - char buffer[4] = {0}; - sprintf(buffer, "%d", value); - return std::string(buffer); -} - -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(bool value) { - return (value)? "true": "false"; -} -# if 0 -// ---------------------------------------------------------------------------- -// Format -// ---------------------------------------------------------------------------- -std::string common_Format(HRESULT result) { - char buffer[10] = {0}; - sprintf(buffer, "%#8x", result); - return std::string(buffer); -} -# endif -// ---------------------------------------------------------------------------- -// ParseUint -// ---------------------------------------------------------------------------- -uint common_ParseUint(std::string text) { - return (uint)atoi(text.c_str( )); -} - -// ---------------------------------------------------------------------------- -// ParseInt -// ---------------------------------------------------------------------------- -int common_ParseInt(std::string text) { - return (int)atoi(text.c_str( )); -} - -// ---------------------------------------------------------------------------- -// ParseWord -// ---------------------------------------------------------------------------- -word common_ParseWord(std::string text) { - return (word)atoi(text.c_str( )); -} - -// ---------------------------------------------------------------------------- -// ParseByte -// ---------------------------------------------------------------------------- -byte common_ParseByte(std::string text) { - return (byte)atoi(text.c_str( )); -} - -// ---------------------------------------------------------------------------- -// ParseBool -// ---------------------------------------------------------------------------- -bool common_ParseBool(std::string text) { - if(text.compare("true") == 0 || text.compare("TRUE") == 0 || text.compare("True") == 0) { - return true; - } - if(atoi(text.c_str( )) == 1) { - return true; - } - return false; -} - -// ---------------------------------------------------------------------------- -// Trim -// ---------------------------------------------------------------------------- -std::string common_Trim(std::string target) { - int index; - for(index = target.length( ) - 1; index >= 0; index--) { - if(target[index] != 0x20 && target[index] != '\n') { - break; - } - } - return target.substr(0, index + 1); -} - -// ---------------------------------------------------------------------------- -// Remove -// ---------------------------------------------------------------------------- -std::string common_Remove(std::string target, char value) { - target.erase(std::remove(target.begin(), target.end(), value), target.end()); - return target; -} - -// ---------------------------------------------------------------------------- -// Replace (string, from, to) -// ---------------------------------------------------------------------------- -std::string common_Replace(std::string target, char value1, char value2) { - int length = 0; - int index; - for(index = 0; index < target.size( ); index++) { - length++; - } - - char* buffer = new char[length + 1]; - for(index = 0; index < target.size( ); index++) { - if(target[index] != value1) { - buffer[index] = target[index]; - } - else - { - buffer[index] = value2; - } - } - - buffer[length] = 0; - std::string source = buffer; - delete[ ] buffer; - return source; -} -# if 0 -// ---------------------------------------------------------------------------- -// GetErrorMessage -// ---------------------------------------------------------------------------- -std::string common_GetErrorMessage( ) { - return common_GetErrorMessage(GetLastError( )); -} - -// ---------------------------------------------------------------------------- -// GetErrorMessage -// ---------------------------------------------------------------------------- -std::string common_GetErrorMessage(DWORD error) { - void* buffer; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buffer, 0, NULL); - std::string message((char*)buffer); - LocalFree(buffer); - return message; -} -# endif -// ---------------------------------------------------------------------------- -// GetExtension -// ---------------------------------------------------------------------------- -std::string common_GetExtension(std::string filename) { - int position = filename.rfind('.'); - if(position != -1) { - return filename.substr(position); - } - return ""; -} diff --git a/core/Common.h b/core/Common.h deleted file mode 100755 index 8d8cfd4..0000000 --- a/core/Common.h +++ /dev/null @@ -1,55 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Common.h -// ---------------------------------------------------------------------------- -#ifndef COMMON_H -#define COMMON_H - -#include -#include - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern std::string common_Format(double value); -extern std::string common_Format(double value, std::string specification); -extern std::string common_Format(uint value); -extern std::string common_Format(word value); -extern std::string common_Format(byte value); -extern std::string common_Format(bool value); -//extern std::string common_Format(HRESULT result); -extern std::string common_Trim(std::string target); -extern std::string common_Remove(std::string target, char value); -extern std::string common_Replace(std::string target, char value1, char value2); -extern std::string common_GetErrorMessage( ); -//extern std::string common_GetErrorMessage(DWORD error); -extern std::string common_GetExtension(std::string filename); -extern uint common_ParseUint(std::string text); -extern int common_ParseInt(std::string text); -extern word common_ParseWord(std::string text); -extern byte common_ParseByte(std::string text); -extern bool common_ParseBool(std::string text); -extern std::string common_defaultPath; - -#endif diff --git a/core/Database.cpp b/core/Database.cpp deleted file mode 100755 index 6c64b4a..0000000 --- a/core/Database.cpp +++ /dev/null @@ -1,139 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Database.cpp -// ---------------------------------------------------------------------------- -#include "Database.h" -#define DATABASE_SOURCE "Database.cpp" - -bool cart_in_db = false; -bool database_enabled = true; -std::string database_filename; - -static std::string database_GetValue(std::string entry) { - int index = entry.rfind('='); - return entry.substr(index + 1); -} - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -void database_Initialize( ) { - database_filename = common_defaultPath + "ProSystem.dat"; -} - -// ---------------------------------------------------------------------------- -// Load -// ---------------------------------------------------------------------------- -bool database_Load(std::string digest) { - cart_in_db = false; - if(database_enabled) { - logger_LogInfo("Accessing database " + database_filename + ".", DATABASE_SOURCE); - - FILE* file = fopen(database_filename.c_str( ), "r"); - if(file == NULL) { - logger_LogError("Failed to open the database for reading.", DATABASE_SOURCE); - return false; - } - - // max count of items in the database - static int count = 17; - - char buffer[256]; - while(fgets(buffer, 256, file) != NULL) { - std::string line = buffer; - if(line.compare(1, 32, digest.c_str( )) == 0) { - cart_in_db = true; - std::string entry[count]; - for (int index = 0; index < count; index++) { - buffer[0] = '\0'; - fgets(buffer, 256, file); - if (strchr(buffer, '[')) { - // Passed the current game in DB - break; - } - entry[index] = common_Remove(buffer, '\n'); - entry[index] = common_Remove(entry[index], '\r'); - } - - cartridge_title = database_GetValue(entry[0]); - cartridge_type = common_ParseByte(database_GetValue(entry[1])); - cartridge_pokey = common_ParseBool(database_GetValue(entry[2])); - cartridge_controller[0] = common_ParseByte(database_GetValue(entry[3])); - cartridge_controller[1] = common_ParseByte(database_GetValue(entry[4])); - cartridge_region = common_ParseByte(database_GetValue(entry[5])); - cartridge_flags = common_ParseUint(database_GetValue(entry[6])); - - // Optionally load the lightgun crosshair offsets, hblank, dual analog - for(int index = 7; index < count; index++) - { - if(entry[index].find("crossx") != std::string::npos) - { - cartridge_crosshair_x = common_ParseInt(database_GetValue(entry[index])); - } - if(entry[index].find("crossy") != std::string::npos) - { - cartridge_crosshair_y = common_ParseInt(database_GetValue(entry[index])); - } - if(entry[index].find("hblank") != std::string::npos) - { - cartridge_hblank = common_ParseInt(database_GetValue(entry[index])); - } - if(entry[index].find("dualanalog") != std::string::npos) - { - cartridge_dualanalog = common_ParseBool(database_GetValue(entry[index])); - } - if (entry[index].find("pokey450") != std::string::npos) { - cartridge_pokey450 = common_ParseBool(database_GetValue(entry[index])); - if (cartridge_pokey450) { - cartridge_pokey = true; - } - } - if (entry[index].find("xm") != std::string::npos) { - cartridge_xm = common_ParseBool(database_GetValue(entry[index])); - } - if (entry[index].find("disablebios") != std::string::npos) { - cartridge_disable_bios = common_ParseBool(database_GetValue(entry[index])); - } - if (entry[index].find("leftswitch") != std::string::npos) { - cartridge_left_switch = common_ParseByte(database_GetValue(entry[index])); - } - if (entry[index].find("rightswitch") != std::string::npos) { - cartridge_right_switch = common_ParseByte(database_GetValue(entry[index])); - } - if (entry[index].find("swapbuttons") != std::string::npos) { - cartridge_swap_buttons = common_ParseBool(database_GetValue(entry[index])); - } - if (entry[index].find("hsc") != std::string::npos) { - cartridge_hsc_enabled = common_ParseBool(database_GetValue(entry[index])); - } - } - break; - } - } - - fclose(file); - } - return true; -} - - diff --git a/core/Hash.cpp b/core/Hash.cpp deleted file mode 100755 index 682ad5a..0000000 --- a/core/Hash.cpp +++ /dev/null @@ -1,235 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Hash.cpp -// ---------------------------------------------------------------------------- -#include "Hash.h" - -// ---------------------------------------------------------------------------- -// Step1 -// ---------------------------------------------------------------------------- -static uint hash_Step1(uint w, uint x, uint y, uint z, uint data, uint s) { - w += (z ^ (x & (y ^ z))) + data; - w = w << s | w >> (32 - s); - w += x; - return w; -} - -// ---------------------------------------------------------------------------- -// Step2 -// ---------------------------------------------------------------------------- -static uint hash_Step2(uint w, uint x, uint y, uint z, uint data, uint s) { - w += (y ^ (z & (x ^ y))) + data; - w = w << s | w >> (32 - s); - w += x; - return w; -} - -// ---------------------------------------------------------------------------- -// Step3 -// ---------------------------------------------------------------------------- -static uint hash_Step3(uint w, uint x, uint y, uint z, uint data, uint s) { - w += (x ^ y ^ z) + data; - w = w << s | w >> (32 - s); - w += x; - return w; -} - -// ---------------------------------------------------------------------------- -// Step4 -// ---------------------------------------------------------------------------- -static uint hash_Step4(uint w, uint x, uint y, uint z, uint data, uint s) { - w += (y ^ (x | ~z)) + data; - w = w << s | w >> (32 - s); - w += x; - return w; -} - -// ---------------------------------------------------------------------------- -// Transform -// ---------------------------------------------------------------------------- -static void hash_Transform(uint out[4], uint in[16]) { - uint a, b, c, d; - - a = out[0]; - b = out[1]; - c = out[2]; - d = out[3]; - - a = hash_Step1(a, b, c, d, in[0] + 0xd76aa478, 7); - d = hash_Step1(d, a, b, c, in[1] + 0xe8c7b756, 12); - c = hash_Step1(c, d, a, b, in[2] + 0x242070db, 17); - b = hash_Step1(b, c, d, a, in[3] + 0xc1bdceee, 22); - a = hash_Step1(a, b, c, d, in[4] + 0xf57c0faf, 7); - d = hash_Step1(d, a, b, c, in[5] + 0x4787c62a, 12); - c = hash_Step1(c, d, a, b, in[6] + 0xa8304613, 17); - b = hash_Step1(b, c, d, a, in[7] + 0xfd469501, 22); - a = hash_Step1(a, b, c, d, in[8] + 0x698098d8, 7); - d = hash_Step1(d, a, b, c, in[9] + 0x8b44f7af, 12); - c = hash_Step1(c, d, a, b, in[10] + 0xffff5bb1, 17); - b = hash_Step1(b, c, d, a, in[11] + 0x895cd7be, 22); - a = hash_Step1(a, b, c, d, in[12] + 0x6b901122, 7); - d = hash_Step1(d, a, b, c, in[13] + 0xfd987193, 12); - c = hash_Step1(c, d, a, b, in[14] + 0xa679438e, 17); - b = hash_Step1(b, c, d, a, in[15] + 0x49b40821, 22); - - a = hash_Step2(a, b, c, d, in[1] + 0xf61e2562, 5); - d = hash_Step2(d, a, b, c, in[6] + 0xc040b340, 9); - c = hash_Step2(c, d, a, b, in[11] + 0x265e5a51, 14); - b = hash_Step2(b, c, d, a, in[0] + 0xe9b6c7aa, 20); - a = hash_Step2(a, b, c, d, in[5] + 0xd62f105d, 5); - d = hash_Step2(d, a, b, c, in[10] + 0x02441453, 9); - c = hash_Step2(c, d, a, b, in[15] + 0xd8a1e681, 14); - b = hash_Step2(b, c, d, a, in[4] + 0xe7d3fbc8, 20); - a = hash_Step2(a, b, c, d, in[9] + 0x21e1cde6, 5); - d = hash_Step2(d, a, b, c, in[14] + 0xc33707d6, 9); - c = hash_Step2(c, d, a, b, in[3] + 0xf4d50d87, 14); - b = hash_Step2(b, c, d, a, in[8] + 0x455a14ed, 20); - a = hash_Step2(a, b, c, d, in[13] + 0xa9e3e905, 5); - d = hash_Step2(d, a, b, c, in[2] + 0xfcefa3f8, 9); - c = hash_Step2(c, d, a, b, in[7] + 0x676f02d9, 14); - b = hash_Step2(b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - a = hash_Step3(a, b, c, d, in[5] + 0xfffa3942, 4); - d = hash_Step3(d, a, b, c, in[8] + 0x8771f681, 11); - c = hash_Step3(c, d, a, b, in[11] + 0x6d9d6122, 16); - b = hash_Step3(b, c, d, a, in[14] + 0xfde5380c, 23); - a = hash_Step3(a, b, c, d, in[1] + 0xa4beea44, 4); - d = hash_Step3(d, a, b, c, in[4] + 0x4bdecfa9, 11); - c = hash_Step3(c, d, a, b, in[7] + 0xf6bb4b60, 16); - b = hash_Step3(b, c, d, a, in[10] + 0xbebfbc70, 23); - a = hash_Step3(a, b, c, d, in[13] + 0x289b7ec6, 4); - d = hash_Step3(d, a, b, c, in[0] + 0xeaa127fa, 11); - c = hash_Step3(c, d, a, b, in[3] + 0xd4ef3085, 16); - b = hash_Step3(b, c, d, a, in[6] + 0x04881d05, 23); - a = hash_Step3(a, b, c, d, in[9] + 0xd9d4d039, 4); - d = hash_Step3(d, a, b, c, in[12] + 0xe6db99e5, 11); - c = hash_Step3(c, d, a, b, in[15] + 0x1fa27cf8, 16); - b = hash_Step3(b, c, d, a, in[2] + 0xc4ac5665, 23); - - a = hash_Step4(a, b, c, d, in[0] + 0xf4292244, 6); - d = hash_Step4(d, a, b, c, in[7] + 0x432aff97, 10); - c = hash_Step4(c, d, a, b, in[14] + 0xab9423a7, 15); - b = hash_Step4(b, c, d, a, in[5] + 0xfc93a039, 21); - a = hash_Step4(a, b, c, d, in[12] + 0x655b59c3, 6); - d = hash_Step4(d, a, b, c, in[3] + 0x8f0ccc92, 10); - c = hash_Step4(c, d, a, b, in[10] + 0xffeff47d, 15); - b = hash_Step4(b, c, d, a, in[1] + 0x85845dd1, 21); - a = hash_Step4(a, b, c, d, in[8] + 0x6fa87e4f, 6); - d = hash_Step4(d, a, b, c, in[15] + 0xfe2ce6e0, 10); - c = hash_Step4(c, d, a, b, in[6] + 0xa3014314, 15); - b = hash_Step4(b, c, d, a, in[13] + 0x4e0811a1, 21); - a = hash_Step4(a, b, c, d, in[4] + 0xf7537e82, 6); - d = hash_Step4(d, a, b, c, in[11] + 0xbd3af235, 10); - c = hash_Step4(c, d, a, b, in[2] + 0x2ad7d2bb, 15); - b = hash_Step4(b, c, d, a, in[9] + 0xeb86d391, 21); - - out[0] += a; - out[1] += b; - out[2] += c; - out[3] += d; -} - -// ---------------------------------------------------------------------------- -// Compute -// ---------------------------------------------------------------------------- -std::string hash_Compute(const byte* source, uint length) { - uint buffer1[4] = {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476}; - uint buffer2[2] = {0}; - byte buffer3[64] = {0}; - - uint temp = buffer2[0]; - if((buffer2[0] = temp + ((uint)length << 3)) < temp) { - buffer2[1]++; - } - buffer2[1] += length >> 29; - - temp = (temp >> 3) & 0x3f; - if(temp) { - byte* ptr = (byte*)buffer3 + temp; - temp = 64 - temp; - if(length < temp) { - for(uint index = 0; index < length; index++) { - ptr[index] = source[index]; - } - } - - for(uint index = 0; index < temp; index++) { - ptr[index] = source[index]; - } - - hash_Transform(buffer1, (uint*)buffer3); - source += temp; - length -= temp; - } - - while(length >= 64) { - for(uint index = 0; index < 64; index++) { - buffer3[index] = source[index]; - } - hash_Transform(buffer1, (uint*)buffer3); - source += 64; - length -= 64; - } - - for(uint index = 0; index < length; index++) { - buffer3[index] = source[index]; - } - - uint count = (buffer2[0] >> 3) & 0x3f; - byte* ptr = buffer3 + count; - *ptr++ = 0x80; - - count = 63 - count; - - if(count < 8) { - for(uint index = 0; index < count; index++) { - ptr[index] = 0; - } - hash_Transform(buffer1, (uint*)buffer3); - - for(uint index = 0; index < 56; index++) { - buffer3[index] = 0; - } - } - else { - for(uint index = 0; index < count - 8; index++) { - ptr[index] = 0; - } - } - - ((uint*)buffer3)[14] = buffer2[0]; - ((uint*)buffer3)[15] = buffer2[1]; - - hash_Transform(buffer1, (uint*)buffer3); - - byte digest[16]; - byte* bufferptr = (byte*)buffer1; - for(uint index = 0; index < 16; index++) { - digest[index] = bufferptr[index]; - } - - char buffer[33] = {0}; - sprintf(buffer, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", digest[0], digest[1], digest[2], digest[3], digest[4], digest[5], digest[6], digest[7], digest[8], digest[9], digest[10], digest[11], digest[12], digest[13], digest[14], digest[15]); - return std::string(buffer); -} - diff --git a/core/Hash.h b/core/Hash.h deleted file mode 100755 index 4ed1502..0000000 --- a/core/Hash.h +++ /dev/null @@ -1,36 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Hash.h -// ---------------------------------------------------------------------------- -#ifndef HASH_H -#define HASH_H - -#include - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern std::string hash_Compute(const byte* source, uint length); - -#endif \ No newline at end of file diff --git a/core/Logger.cpp b/core/Logger.cpp deleted file mode 100755 index e2df055..0000000 --- a/core/Logger.cpp +++ /dev/null @@ -1,164 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Logger.cpp -// ---------------------------------------------------------------------------- -#include "Logger.h" -#define LOGGER_FILENAME "ProSystem.log" -#include - -byte logger_level = LOGGER_LEVEL_DEBUG; -static FILE* logger_file = NULL; -char a[255]=""; - -// ---------------------------------------------------------------------------- -// GetTime -// ---------------------------------------------------------------------------- -static std::string logger_GetTime( ) { - time_t current; - time(¤t); - std::string timestring = ctime(¤t); - return timestring.erase(timestring.find_first_of("\n"), 1); -} - -// ---------------------------------------------------------------------------- -// Log -// ---------------------------------------------------------------------------- -static void logger_Log(std::string message, byte level, std::string source) { - if(logger_file != NULL) { - std::string entry = "[" + logger_GetTime( ) + "]"; - switch(level) { - case LOGGER_LEVEL_ERROR: - entry += "[ERROR]"; - break; - case LOGGER_LEVEL_INFO: - entry += "[INFO ]"; - break; - default: - entry += "[DEBUG]"; - break; - } - entry += " " + message; - if(source.length( ) > 0) { - entry += " " + source; - } - entry += "\n"; - fwrite(entry.c_str( ), 1, entry.length( ), logger_file); - fflush(logger_file); - } -} - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -bool logger_Initialize( ) { - logger_file = fopen(LOGGER_FILENAME, "w"); - return (logger_file != NULL); -} - -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -bool logger_Initialize(std::string filename) { - logger_file = fopen(filename.c_str( ), "w"); - return (logger_file != NULL); -} - - -// ---------------------------------------------------------------------------- -// LogError ////////// -// ---------------------------------------------------------------------------- -void logger_LogError(int message, std::string source) { - std::cerr << message << source << std::endl; - if(logger_level == LOGGER_LEVEL_ERROR || logger_level == LOGGER_LEVEL_INFO || logger_level == LOGGER_LEVEL_DEBUG) { -// LoadString(GetModuleHandle(NULL),message, a, 180); -// std::string b(a); -// logger_Log(b, LOGGER_LEVEL_ERROR, source); - logger_LogError(message, ""); - } -} - -// ---------------------------------------------------------------------------- -// LogError -// ---------------------------------------------------------------------------- -void logger_LogError(std::string message, std::string source) { - std::cerr << message << source << std::endl; - if(logger_level == LOGGER_LEVEL_ERROR || logger_level == LOGGER_LEVEL_INFO || logger_level == LOGGER_LEVEL_DEBUG) { - logger_Log(message, LOGGER_LEVEL_ERROR, source); - } -} - - -// ---------------------------------------------------------------------------- -// LogInfo -// ---------------------------------------------------------------------------- -void logger_LogInfo(int message, std::string source) { - std::cerr << message << source << std::endl; - if(logger_level == LOGGER_LEVEL_INFO || logger_level == LOGGER_LEVEL_DEBUG) { -// LoadString(GetModuleHandle(NULL),message, a, 180); -// std::string b(a); -// logger_Log(b, LOGGER_LEVEL_INFO, source); - logger_LogDebug(message, ""); - } -} - -// ---------------------------------------------------------------------------- -// LogInfo ///////// -// ---------------------------------------------------------------------------- -void logger_LogInfo(std::string message, std::string source) { - std::cerr << message << source << std::endl; - if(logger_level == LOGGER_LEVEL_INFO || logger_level == LOGGER_LEVEL_DEBUG) { - logger_Log(message, LOGGER_LEVEL_INFO, source); - } -} - -// ---------------------------------------------------------------------------- -// LogDebug //////////// -// ---------------------------------------------------------------------------- -void logger_LogDebug(int message, std::string source) { - std::cerr << message << source << std::endl; - if(logger_level == LOGGER_LEVEL_DEBUG) { -// LoadString(GetModuleHandle(NULL),message, a, 180); -// std::string b(a); -// logger_Log(b, LOGGER_LEVEL_DEBUG, source); - logger_LogDebug(message, ""); - } -} - -// ---------------------------------------------------------------------------- -// LogDebug -// ---------------------------------------------------------------------------- -void logger_LogDebug(std::string message, std::string source) { - std::cerr << message << source << std::endl; - if(logger_level == LOGGER_LEVEL_DEBUG) { - logger_Log(message, LOGGER_LEVEL_DEBUG, source); - } -} - -// ---------------------------------------------------------------------------- -// Release -// ---------------------------------------------------------------------------- -void logger_Release( ) { - if(logger_file != NULL) { - fclose(logger_file); - } -} \ No newline at end of file diff --git a/core/Logger.h b/core/Logger.h deleted file mode 100755 index d042406..0000000 --- a/core/Logger.h +++ /dev/null @@ -1,53 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Logger.h -// ---------------------------------------------------------------------------- -#ifndef LOGGER_H -#define LOGGER_H -#define LOGGER_LEVEL_DEBUG 0 -#define LOGGER_LEVEL_INFO 1 -#define LOGGER_LEVEL_ERROR 2 - -#include -#include -#include -//#include "Windows.h" -//#include "Resource.h" - - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern bool logger_Initialize( ); -extern bool logger_Initialize(std::string filename); -extern void logger_LogError(std::string message, std::string source); -extern void logger_LogError(int message, std::string source); -extern void logger_LogInfo(std::string message, std::string source); -extern void logger_LogInfo(int message, std::string source); -extern void logger_LogDebug(std::string message, std::string source); -extern void logger_LogDebug(int, std::string source); -extern void logger_Release( ); -extern byte logger_level; - -#endif \ No newline at end of file diff --git a/core/Maria.cpp b/core/Maria.cpp deleted file mode 100755 index 9d925e5..0000000 --- a/core/Maria.cpp +++ /dev/null @@ -1,352 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Maria.c -// ---------------------------------------------------------------------------- -#include "Maria.h" -#define MARIA_LINERAM_SIZE 160 - -rect maria_displayArea = {0, 16, 319, 258}; -rect maria_visibleArea = {0, 26, 319, 248}; -byte maria_surface[MARIA_SURFACE_SIZE] = {0}; -word maria_scanline = 1; - -static byte maria_lineRAM[MARIA_LINERAM_SIZE]; -static uint maria_cycles; -static pair maria_dpp; -static pair maria_dp; -static pair maria_pp; -static byte maria_horizontal; -static byte maria_palette; -static signed char maria_offset; -static byte maria_h08; -static byte maria_h16; -static byte maria_wmode; - -// ---------------------------------------------------------------------------- -// StoreCell -// ---------------------------------------------------------------------------- -static inline void maria_StoreCell(byte data) { - if(maria_horizontal < MARIA_LINERAM_SIZE) { - if(data) { - maria_lineRAM[maria_horizontal] = maria_palette | data; - } - else { - byte kmode = memory_ram[CTRL] & 4; - if(kmode) { - maria_lineRAM[maria_horizontal] = 0; - } - } - } - maria_horizontal++; -} - -// ---------------------------------------------------------------------------- -// StoreCell -// ---------------------------------------------------------------------------- -static inline void maria_StoreCell(byte high, byte low) { - if(maria_horizontal < MARIA_LINERAM_SIZE) { - if(low || high) { - maria_lineRAM[maria_horizontal] = (maria_palette & 16) | high | low; - } - else { - byte kmode = memory_ram[CTRL] & 4; - if(kmode) { - maria_lineRAM[maria_horizontal] = 0; - } - } - } - maria_horizontal++; -} - -// ---------------------------------------------------------------------------- -// IsHolyDMA -// ---------------------------------------------------------------------------- -static inline bool maria_IsHolyDMA( ) { - if(maria_pp.w > 32767) { - if(maria_h16 && (maria_pp.w & 4096)) { - return true; - } - if(maria_h08 && (maria_pp.w & 2048)) { - return true; - } - } - return false; -} - -// ---------------------------------------------------------------------------- -// GetColor -// ---------------------------------------------------------------------------- -static inline byte maria_GetColor(byte data) { - if(data & 3) { - return memory_ram[BACKGRND + data]; - } - else { - return memory_ram[BACKGRND]; - } -} - -// ---------------------------------------------------------------------------- -// StoreGraphic -// ---------------------------------------------------------------------------- -static inline void maria_StoreGraphic( ) { - byte data = memory_ram[maria_pp.w]; - if(maria_wmode) { - if(maria_IsHolyDMA( )) { -#if 0 // Wii: disabled due to rendering in Kangaroo mode - maria_StoreCell(0, 0); - maria_StoreCell(0, 0); -#endif - maria_horizontal+=2; - } - else { - maria_StoreCell((data & 12), (data & 192) >> 6); - maria_StoreCell((data & 48) >> 4, (data & 3) << 2); - } - } - else { - if(maria_IsHolyDMA( )) { -#if 0 // Wii: disabled due to rendering in Kangaroo mode - maria_StoreCell(0); - maria_StoreCell(0); - maria_StoreCell(0); - maria_StoreCell(0); -#endif - maria_horizontal+=4; - } - else { - maria_StoreCell((data & 192) >> 6); - maria_StoreCell((data & 48) >> 4); - maria_StoreCell((data & 12) >> 2); - maria_StoreCell(data & 3); - } - } - maria_pp.w++; -} - -// ---------------------------------------------------------------------------- -// WriteLineRAM -// ---------------------------------------------------------------------------- -static inline void maria_WriteLineRAM(byte* buffer) { - byte rmode = memory_ram[CTRL] & 3; - if(rmode == 0) { - // 160A/B - int pixel = 0; - for(int index = 0; index < MARIA_LINERAM_SIZE; index += 4) { - word color; - color = maria_GetColor(maria_lineRAM[index + 0]); - buffer[pixel++] = color; - buffer[pixel++] = color; - color = maria_GetColor(maria_lineRAM[index + 1]); - buffer[pixel++] = color; - buffer[pixel++] = color; - color = maria_GetColor(maria_lineRAM[index + 2]); - buffer[pixel++] = color; - buffer[pixel++] = color; - color = maria_GetColor(maria_lineRAM[index + 3]); - buffer[pixel++] = color; - buffer[pixel++] = color; - } - } - else if(rmode == 2) { - // 320B/D - int pixel = 0; - for(int index = 0; index < MARIA_LINERAM_SIZE; index += 4) { - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 0] & 16) | ((maria_lineRAM[index + 0] & 8) >> 3) | ((maria_lineRAM[index + 0] & 2))); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 0] & 16) | ((maria_lineRAM[index + 0] & 4) >> 2) | ((maria_lineRAM[index + 0] & 1) << 1)); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 1] & 16) | ((maria_lineRAM[index + 1] & 8) >> 3) | ((maria_lineRAM[index + 1] & 2))); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 1] & 16) | ((maria_lineRAM[index + 1] & 4) >> 2) | ((maria_lineRAM[index + 1] & 1) << 1)); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 2] & 16) | ((maria_lineRAM[index + 2] & 8) >> 3) | ((maria_lineRAM[index + 2] & 2))); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 2] & 16) | ((maria_lineRAM[index + 2] & 4) >> 2) | ((maria_lineRAM[index + 2] & 1) << 1)); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 3] & 16) | ((maria_lineRAM[index + 3] & 8) >> 3) | ((maria_lineRAM[index + 3] & 2))); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 3] & 16) | ((maria_lineRAM[index + 3] & 4) >> 2) | ((maria_lineRAM[index + 3] & 1) << 1)); - } - } - else if(rmode == 3) { - // 320A/C - int pixel = 0; - for(int index = 0; index < MARIA_LINERAM_SIZE; index += 4) { - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 0] & 30)); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 0] & 28) | ((maria_lineRAM[index + 0] & 1) << 1)); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 1] & 30)); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 1] & 28) | ((maria_lineRAM[index + 1] & 1) << 1)); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 2] & 30)); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 2] & 28) | ((maria_lineRAM[index + 2] & 1) << 1)); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 3] & 30)); - buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 3] & 28) | ((maria_lineRAM[index + 3] & 1) << 1)); - } - } -} - -// ---------------------------------------------------------------------------- -// StoreLineRAM -// ---------------------------------------------------------------------------- -static inline void maria_StoreLineRAM( ) { - for(int index = 0; index < MARIA_LINERAM_SIZE; index++) { - maria_lineRAM[index] = 0; - } - - byte mode = memory_ram[maria_dp.w + 1]; - while(mode & 0x5f) { - byte width; - byte indirect = 0; - - maria_pp.b.l = memory_ram[maria_dp.w]; - maria_pp.b.h = memory_ram[maria_dp.w + 2]; - - if(mode & 31) { - maria_cycles += 8; // Maria cycles (Header 4 byte) - maria_palette = (memory_ram[maria_dp.w + 1] & 224) >> 3; - maria_horizontal = memory_ram[maria_dp.w + 3]; - width = memory_ram[maria_dp.w + 1] & 31; - width = ((~width) & 31) + 1; - maria_dp.w += 4; - } - else { - maria_cycles += 12; // Maria cycles (Header 5 byte) - maria_palette = (memory_ram[maria_dp.w + 3] & 224) >> 3; - maria_horizontal = memory_ram[maria_dp.w + 4]; - indirect = memory_ram[maria_dp.w + 1] & 32; - maria_wmode = memory_ram[maria_dp.w + 1] & 128; - width = memory_ram[maria_dp.w + 3] & 31; - width = (width == 0)? 32: ((~width) & 31) + 1; - maria_dp.w += 5; - } - - if(!indirect) { - maria_pp.b.h += maria_offset; - for(int index = 0; index < width; index++) { - maria_cycles += 3; // Maria cycles (Direct graphic read) - maria_StoreGraphic( ); - } - } - else { - byte cwidth = memory_ram[CTRL] & 16; - pair basePP = maria_pp; - for(int index = 0; index < width; index++) { - maria_cycles += 3; // Maria cycles (Indirect) - maria_pp.b.l = memory_ram[basePP.w++]; - maria_pp.b.h = memory_ram[CHARBASE] + maria_offset; - maria_cycles += 3; // Maria cycles (Indirect, 1 byte) - maria_StoreGraphic( ); - if(cwidth) { - maria_cycles += 3; // Maria cycles (Indirect, 2 bytes) - maria_StoreGraphic( ); - } - } - } - mode = memory_ram[maria_dp.w + 1]; - } -} - -// ---------------------------------------------------------------------------- -// Reset -// ---------------------------------------------------------------------------- -void maria_Reset( ) { - maria_scanline = 1; - for(int index = 0; index < MARIA_SURFACE_SIZE; index++) { - maria_surface[index] = 0; - } - - maria_cycles = 0; - maria_dpp.w = 0; - maria_dp.w = 0; - maria_pp.w = 0; - maria_horizontal = 0; - maria_palette = 0; - maria_offset = 0; - maria_h08 = 0; - maria_h16 = 0; - maria_wmode = 0; -} - -// ---------------------------------------------------------------------------- -// RenderScanline -// ---------------------------------------------------------------------------- -uint maria_RenderScanline( ) { - maria_cycles = 0; - - // lightgun flash - // Displays the background color when Maria is disabled (if applicable) - if( ( ( memory_ram[CTRL] & 96 ) != 64 ) && - maria_scanline >= maria_visibleArea.top && - maria_scanline <= maria_visibleArea.bottom ) { - byte bgcolor = maria_GetColor(0); - byte *bgstart = maria_surface + ((maria_scanline - maria_displayArea.top) * maria_displayArea.GetLength()); - for(uint index = 0; index < MARIA_LINERAM_SIZE; index++ ) { - *bgstart++ = bgcolor; - *bgstart++ = bgcolor; - } - } - - if((memory_ram[CTRL] & 96) == 64 && maria_scanline >= maria_displayArea.top && maria_scanline <= maria_displayArea.bottom) { - maria_cycles += 5; // Maria cycles (DMA Startup) - if(maria_scanline == maria_displayArea.top) { - maria_cycles += 10; // Maria cycles (End of VBLANK) - maria_dpp.b.l = memory_ram[DPPL]; - maria_dpp.b.h = memory_ram[DPPH]; - maria_h08 = memory_ram[maria_dpp.w] & 32; - maria_h16 = memory_ram[maria_dpp.w] & 64; - maria_offset = memory_ram[maria_dpp.w] & 15; - maria_dp.b.l = memory_ram[maria_dpp.w + 2]; - maria_dp.b.h = memory_ram[maria_dpp.w + 1]; - if(memory_ram[maria_dpp.w] & 128) { - maria_cycles += 20; // Maria cycles (NMI) /*29, 16, 20*/ - sally_ExecuteNMI( ); - } - } - else if(maria_scanline >= maria_visibleArea.top && maria_scanline <= maria_visibleArea.bottom) { - maria_WriteLineRAM(maria_surface + ((maria_scanline - maria_displayArea.top) * maria_displayArea.GetLength( ))); - } - if(maria_scanline != maria_displayArea.bottom) { - maria_dp.b.l = memory_ram[maria_dpp.w + 2]; - maria_dp.b.h = memory_ram[maria_dpp.w + 1]; - maria_StoreLineRAM( ); - maria_offset--; - if(maria_offset < 0) { - maria_cycles += 10; // Maria cycles (Last line of zone) /*20*/ - maria_dpp.w += 3; - maria_h08 = memory_ram[maria_dpp.w] & 32; - maria_h16 = memory_ram[maria_dpp.w] & 64; - maria_offset = memory_ram[maria_dpp.w] & 15; - if(memory_ram[maria_dpp.w] & 128) { - maria_cycles += 20; // Maria cycles (NMI) /*29, 16, 20*/ - sally_ExecuteNMI( ); - } - } - else - { - maria_cycles += 4; // Maria cycles (Other lines of zone) - } - } - } - return maria_cycles; -} - -// ---------------------------------------------------------------------------- -// Clear -// ---------------------------------------------------------------------------- -void maria_Clear( ) { - for(int index = 0; index < MARIA_SURFACE_SIZE; index++) { - maria_surface[index] = 0; - } -} diff --git a/core/Memory.cpp b/core/Memory.cpp deleted file mode 100755 index 26da85d..0000000 --- a/core/Memory.cpp +++ /dev/null @@ -1,216 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Memory.cpp -// ---------------------------------------------------------------------------- -#include "Memory.h" -#include "ExpansionModule.h" - -byte memory_ram[MEMORY_SIZE] = {0}; -byte memory_rom[MEMORY_SIZE] = {0}; - -// ---------------------------------------------------------------------------- -// Reset -// ---------------------------------------------------------------------------- -void memory_Reset( ) { - uint index; - for(index = 0; index < MEMORY_SIZE; index++) { - memory_ram[index] = 0; - memory_rom[index] = 1; - } - for(index = 0; index < 16384; index++) { - memory_rom[index] = 0; - } -} -// ---------------------------------------------------------------------------- -// Read -// ---------------------------------------------------------------------------- -byte memory_Read(word address) { - byte tmp_byte; - - if (cartridge_xm) { - if ((address >= 0x0470 && address < 0x0480) || - (xm_pokey_enabled && (address >= 0x0450 && address < 0x0470)) || - (xm_mem_enabled && (address >= 0x4000 && address < 0x8000))) { - return xm_Read(address); - } - } - - if (cartridge_pokey && ( - (!cartridge_pokey450 && (address >= 0x4000 && address <= 0x400f)) || - (cartridge_pokey450 && (address >= 0x0450 && address < 0x0470)))) { - return pokey_GetRegister( - cartridge_pokey450 ? 0x4000 + (address - 0x0450) : address); - } - - switch ( address ) { - case INTIM: - case INTIM | 0x2: - memory_ram[INTFLG] &= 0x7f; - return memory_ram[INTIM]; - break; - case INTFLG: - case INTFLG | 0x2: - tmp_byte = memory_ram[INTFLG]; - memory_ram[INTFLG] &= 0x7f; - return tmp_byte; - break; - default: - return memory_ram[address]; - break; - } -} - -// ---------------------------------------------------------------------------- -// Write -// ---------------------------------------------------------------------------- -void memory_Write(word address, byte data) { - if (cartridge_xm && - ((address >= 0x0470 && address < 0x0480) || - ((xm_pokey_enabled && (address >= 0x0450 && address < 0x0470)) || - (xm_mem_enabled && (address >= 0x4000 && address < 0x8000))))) { - xm_Write(address, data); - return; - } - - if (cartridge_pokey && ( - (!cartridge_pokey450 && (address >= 0x4000 && address <= 0x400f)) || - (cartridge_pokey450 && (address >= 0x0450 && address < 0x0470)))) { - pokey_SetRegister( - (cartridge_pokey450 ? 0x4000 + (address - 0x0450) : address), data); - return; - } - - if(!memory_rom[address]) { - switch(address) { - case WSYNC: - if(!(cartridge_flags & 128)) { - memory_ram[WSYNC] = true; - } - break; - case INPTCTRL: - if(data == 22 && cartridge_IsLoaded( )) { - cartridge_Store( ); - } - else if(data == 2 && bios_enabled) { - bios_Store( ); - } - break; - case INPT0: - break; - case INPT1: - break; - case INPT2: - break; - case INPT3: - break; - case INPT4: - break; - case INPT5: - break; - case AUDC0: - tia_SetRegister(AUDC0, data); - break; - case AUDC1: - tia_SetRegister(AUDC1, data); - break; - case AUDF0: - tia_SetRegister(AUDF0, data); - break; - case AUDF1: - tia_SetRegister(AUDF1, data); - break; - case AUDV0: - tia_SetRegister(AUDV0, data); - break; - case AUDV1: - tia_SetRegister(AUDV1, data); - break; - case SWCHA: /*gdement: Writing here actually writes to DRA inside the RIOT chip. - This value only indirectly affects output of SWCHA. Ditto for SWCHB.*/ - riot_SetDRA(data); - break; - case SWCHB: - riot_SetDRB(data); - break; - case TIM1T: - case TIM1T | 0x8: - riot_SetTimer(TIM1T, data); - break; - case TIM8T: - case TIM8T | 0x8: - riot_SetTimer(TIM8T, data); - break; - case TIM64T: - case TIM64T | 0x8: - riot_SetTimer(TIM64T, data); - break; - case T1024T: - case T1024T | 0x8: - riot_SetTimer(T1024T, data); - break; - default: - memory_ram[address] = data; - if(address >= 8256 && address <= 8447) { - memory_ram[address - 8192] = data; - } - else if(address >= 8512 && address <= 8702) { - memory_ram[address - 8192] = data; - } - else if(address >= 64 && address <= 255) { - memory_ram[address + 8192] = data; - } - else if(address >= 320 && address <= 511) { - memory_ram[address + 8192] = data; - } - break; - /*TODO: gdement: test here for debug port. Don't put it in the switch because that will change behavior.*/ - } - } - else { - cartridge_Write(address, data); - } -} - -// ---------------------------------------------------------------------------- -// WriteROM -// ---------------------------------------------------------------------------- -void memory_WriteROM(word address, uint size, const byte* data) { - if((address + size) <= MEMORY_SIZE && data != NULL) { - for(uint index = 0; index < size; index++) { - memory_ram[address + index] = data[index]; - memory_rom[address + index] = 1; - } - } -} - -// ---------------------------------------------------------------------------- -// ClearROM -// ---------------------------------------------------------------------------- -void memory_ClearROM(word address, uint size) { - if((address + size) <= MEMORY_SIZE) { - for(uint index = 0; index < size; index++) { - memory_ram[address + index] = 0; - memory_rom[address + index] = 0; - } - } -} diff --git a/core/Palette.cpp b/core/Palette.cpp deleted file mode 100755 index dd3ae2b..0000000 --- a/core/Palette.cpp +++ /dev/null @@ -1,132 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Palette.h -// ---------------------------------------------------------------------------- -#include "Palette.h" -#define PALETTE_SOURCE "Palette.cpp" - -std::string palette_filename; -bool palette_default = true; -byte palette_data[PALETTE_SIZE] = { -0x00,0x00,0x00,0x25,0x25,0x25,0x34,0x34,0x34,0x4F,0x4F,0x4F, -0x5B,0x5B,0x5B,0x69,0x69,0x69,0x7B,0x7B,0x7B,0x8A,0x8A,0x8A, -0xA7,0xA7,0xA7,0xB9,0xB9,0xB9,0xC5,0xC5,0xC5,0xD0,0xD0,0xD0, -0xD7,0xD7,0xD7,0xE1,0xE1,0xE1,0xF4,0xF4,0xF4,0xFF,0xFF,0xFF, -0x4C,0x32,0x00,0x62,0x3A,0x00,0x7B,0x4A,0x00,0x9A,0x60,0x00, -0xB5,0x74,0x00,0xCC,0x85,0x00,0xE7,0x9E,0x08,0xF7,0xAF,0x10, -0xFF,0xC3,0x18,0xFF,0xD0,0x20,0xFF,0xD8,0x28,0xFF,0xDF,0x30, -0xFF,0xE6,0x3B,0xFF,0xF4,0x40,0xFF,0xFA,0x4B,0xFF,0xFF,0x50, -0x99,0x25,0x00,0xAA,0x25,0x00,0xB4,0x25,0x00,0xD3,0x30,0x00, -0xDD,0x48,0x02,0xE2,0x50,0x09,0xF4,0x67,0x00,0xF4,0x75,0x10, -0xFF,0x9E,0x10,0xFF,0xAC,0x20,0xFF,0xBA,0x3A,0xFF,0xBF,0x50, -0xFF,0xC6,0x6D,0xFF,0xD5,0x80,0xFF,0xE4,0x90,0xFF,0xE6,0x99, -0x98,0x0C,0x0C,0x99,0x0C,0x0C,0xC2,0x13,0x00,0xD3,0x13,0x00, -0xE2,0x35,0x00,0xE3,0x40,0x00,0xE4,0x40,0x20,0xE5,0x52,0x30, -0xFD,0x78,0x54,0xFF,0x8A,0x6A,0xFF,0x98,0x7C,0xFF,0xA4,0x8B, -0xFF,0xB3,0x9E,0xFF,0xC2,0xB2,0xFF,0xD0,0xBA,0xFF,0xD7,0xC0, -0x99,0x00,0x00,0xA9,0x00,0x00,0xC2,0x04,0x00,0xD3,0x04,0x00, -0xDA,0x04,0x00,0xDB,0x08,0x00,0xE4,0x20,0x20,0xF6,0x40,0x40, -0xFB,0x70,0x70,0xFB,0x7E,0x7E,0xFB,0x8F,0x8F,0xFF,0x9F,0x9F, -0xFF,0xAB,0xAB,0xFF,0xB9,0xB9,0xFF,0xC9,0xC9,0xFF,0xCF,0xCF, -0x7E,0x00,0x50,0x80,0x00,0x50,0x80,0x00,0x5F,0x95,0x0B,0x74, -0xAA,0x22,0x88,0xBB,0x2F,0x9A,0xCE,0x3F,0xAD,0xD7,0x5A,0xB6, -0xE4,0x67,0xC3,0xEF,0x72,0xCE,0xFB,0x7E,0xDA,0xFF,0x8D,0xE1, -0xFF,0x9D,0xE5,0xFF,0xA5,0xE7,0xFF,0xAF,0xEA,0xFF,0xB8,0xEC, -0x48,0x00,0x6C,0x5C,0x04,0x88,0x65,0x0D,0x90,0x7B,0x23,0xA7, -0x93,0x3B,0xBF,0x9D,0x45,0xC9,0xA7,0x4F,0xD3,0xB2,0x5A,0xDE, -0xBD,0x65,0xE9,0xC5,0x6D,0xF1,0xCE,0x76,0xFA,0xD5,0x83,0xFF, -0xDA,0x90,0xFF,0xDE,0x9C,0xFF,0xE2,0xA9,0xFF,0xE6,0xB6,0xFF, -0x1B,0x00,0x70,0x22,0x1B,0x8D,0x37,0x30,0xA2,0x48,0x41,0xB3, -0x59,0x52,0xC4,0x63,0x5C,0xCE,0x6F,0x68,0xDA,0x7D,0x76,0xE8, -0x87,0x80,0xF8,0x93,0x8C,0xFF,0x9D,0x97,0xFF,0xA8,0xA3,0xFF, -0xB3,0xAF,0xFF,0xBC,0xB8,0xFF,0xC4,0xC1,0xFF,0xDA,0xD1,0xFF, -0x00,0x0D,0x7F,0x00,0x12,0xA7,0x00,0x18,0xC0,0x0A,0x2B,0xD1, -0x1B,0x4A,0xE3,0x2F,0x58,0xF0,0x37,0x68,0xFF,0x49,0x79,0xFF, -0x5B,0x85,0xFF,0x6D,0x96,0xFF,0x7F,0xA3,0xFF,0x8C,0xAD,0xFF, -0x96,0xB4,0xFF,0xA8,0xC0,0xFF,0xB7,0xCB,0xFF,0xC6,0xD6,0xFF, -0x00,0x29,0x5A,0x00,0x38,0x76,0x00,0x48,0x92,0x00,0x5C,0xAC, -0x00,0x71,0xC6,0x00,0x86,0xD0,0x0A,0x9B,0xDF,0x1A,0xA8,0xEC, -0x2B,0xB6,0xFF,0x3F,0xC2,0xFF,0x45,0xCB,0xFF,0x59,0xD3,0xFF, -0x7F,0xDA,0xFF,0x8F,0xDE,0xFF,0xA0,0xE2,0xFF,0xB0,0xEB,0xFF, -0x00,0x38,0x39,0x00,0x3C,0x48,0x00,0x3D,0x5B,0x02,0x66,0x7F, -0x03,0x73,0x83,0x00,0x9C,0xAA,0x00,0xA1,0xBB,0x01,0xA4,0xCC, -0x03,0xBB,0xFF,0x05,0xDA,0xE2,0x18,0xE5,0xFF,0x34,0xEA,0xFF, -0x49,0xEF,0xFF,0x66,0xF2,0xFF,0x84,0xF4,0xFF,0x9E,0xF9,0xFF, -0x00,0x4A,0x00,0x00,0x5D,0x00,0x00,0x70,0x00,0x00,0x8B,0x00, -0x00,0xA9,0x00,0x00,0xBB,0x05,0x00,0xBD,0x00,0x02,0xD0,0x05, -0x1A,0xD5,0x40,0x5A,0xF1,0x77,0x82,0xEF,0xA7,0x84,0xED,0xD1, -0x89,0xFF,0xED,0x7D,0xFF,0xFF,0x93,0xFF,0xFF,0x9B,0xFF,0xFF, -0x22,0x4A,0x03,0x27,0x53,0x04,0x30,0x64,0x05,0x3C,0x77,0x0C, -0x45,0x8C,0x11,0x5A,0xA5,0x13,0x1B,0xD2,0x09,0x1F,0xDD,0x00, -0x3D,0xCD,0x2D,0x3D,0xCD,0x30,0x58,0xCC,0x40,0x60,0xD3,0x50, -0xA2,0xEC,0x55,0xB3,0xF2,0x4A,0xBB,0xF6,0x5D,0xC4,0xF8,0x70, -0x2E,0x3F,0x0C,0x36,0x4A,0x0F,0x40,0x56,0x15,0x46,0x5F,0x17, -0x57,0x77,0x1A,0x65,0x85,0x1C,0x74,0x93,0x1D,0x8F,0xA5,0x25, -0xAD,0xB7,0x2C,0xBC,0xC7,0x30,0xC9,0xD5,0x33,0xD4,0xE0,0x3B, -0xE0,0xEC,0x42,0xEA,0xF6,0x45,0xF0,0xFD,0x47,0xF4,0xFF,0x6F, -0x55,0x24,0x00,0x5A,0x2C,0x00,0x6C,0x3B,0x00,0x79,0x4B,0x00, -0xB9,0x75,0x00,0xBB,0x85,0x00,0xC1,0xA1,0x20,0xD0,0xB0,0x2F, -0xDE,0xBE,0x3F,0xE6,0xC6,0x45,0xED,0xCD,0x57,0xF5,0xDB,0x62, -0xFB,0xE5,0x69,0xFC,0xEE,0x6F,0xFD,0xF3,0x77,0xFD,0xF3,0x7F, -0x5C,0x27,0x00,0x5C,0x2F,0x00,0x71,0x3B,0x00,0x7B,0x48,0x00, -0xB9,0x68,0x20,0xBB,0x72,0x20,0xC5,0x86,0x29,0xD7,0x96,0x33, -0xE6,0xA4,0x40,0xF4,0xB1,0x4B,0xFD,0xC1,0x58,0xFF,0xCC,0x55, -0xFF,0xD4,0x61,0xFF,0xDD,0x69,0xFF,0xE6,0x79,0xFF,0xEA,0x98 -}; - -// ---------------------------------------------------------------------------- -// Load -// ---------------------------------------------------------------------------- -bool palette_Load(std::string filename) { - if(filename.empty( ) || filename.length( ) == 0) { - logger_LogError("Palette filename is invalid.", PALETTE_SOURCE); - return false; - } - - logger_LogInfo("Opening palette file " + filename + ".", PALETTE_SOURCE); - - FILE* file = fopen(filename.c_str( ), "rb"); - if(file == NULL) { - logger_LogError("Failed to open the palette file " + filename + " for reading.", PALETTE_SOURCE); - return false; - } - - if(fread(palette_data, 1, PALETTE_SIZE, file) != PALETTE_SIZE) { - fclose(file); - logger_LogError("Failed to read the palette data.", PALETTE_SOURCE); - return false; - } - - fclose(file); - palette_filename = filename; - return true; -} - -// ---------------------------------------------------------------------------- -// Load -// ---------------------------------------------------------------------------- -void palette_Load(const byte* data) { - for(int index = 0; index < PALETTE_SIZE; index++) { - palette_data[index] = data[index]; - } -} diff --git a/core/Pokey.cpp b/core/Pokey.cpp deleted file mode 100755 index 1f0a437..0000000 --- a/core/Pokey.cpp +++ /dev/null @@ -1,512 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// PokeySound is Copyright(c) 1997 by Ron Fries -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of version 2 of the GNU Library General Public License -// as published by the Free Software Foundation. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library -// General Public License for more details. -// To obtain a copy of the GNU Library General Public License, write to the -// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// -// Any permitted reproduction of these routines, in whole or in part, must -// bear this legend. -// ---------------------------------------------------------------------------- -// Pokey.cpp -// ---------------------------------------------------------------------------- - -#include -#include "Pokey.h" -#include "ProSystem.h" -#define POKEY_NOTPOLY5 0x80 -#define POKEY_POLY4 0x40 -#define POKEY_PURE 0x20 -#define POKEY_VOLUME_ONLY 0x10 -#define POKEY_VOLUME_MASK 0x0f -#define POKEY_POLY9 0x80 -#define POKEY_CH1_179 0x40 -#define POKEY_CH3_179 0x20 -#define POKEY_CH1_CH2 0x10 -#define POKEY_CH3_CH4 0x08 -#define POKEY_CH1_FILTER 0x04 -#define POKEY_CH2_FILTER 0x02 -#define POKEY_CLOCK_15 0x01 -#define POKEY_DIV_64 28 -#define POKEY_DIV_15 114 -#define POKEY_POLY4_SIZE 0x000f -#define POKEY_POLY5_SIZE 0x001f -#define POKEY_POLY9_SIZE 0x01ff -#define POKEY_POLY17_SIZE 0x0001ffff -#define POKEY_CHANNEL1 0 -#define POKEY_CHANNEL2 1 -#define POKEY_CHANNEL3 2 -#define POKEY_CHANNEL4 3 -#define POKEY_SAMPLE 4 - -#define SK_RESET 0x03 - -byte pokey_buffer[POKEY_BUFFER_SIZE] = {0}; -uint pokey_size = (POKEY_BUFFER_SIZE - 512); // 524 previously - -static uint pokey_frequency = 1787520; -static uint pokey_sampleRate = 31440; -static uint pokey_soundCntr = 0; -static byte pokey_audf[4]; -static byte pokey_audc[4]; -static byte pokey_audctl; -static byte pokey_output[4]; -static byte pokey_outVol[4]; -static byte pokey_poly04[POKEY_POLY4_SIZE] = {1,1,0,1,1,1,0,0,0,0,1,0,1,0,0}; -static byte pokey_poly05[POKEY_POLY5_SIZE] = {0,0,1,1,0,0,0,1,1,1,1,0,0,1,0,1,0,1,1,0,1,1,1,0,1,0,0,0,0,0,1}; -static byte pokey_poly17[POKEY_POLY17_SIZE]; -static uint pokey_poly17Size; -static uint pokey_polyAdjust; -static uint pokey_poly04Cntr; -static uint pokey_poly05Cntr; -static uint pokey_poly17Cntr; -static uint pokey_divideMax[4]; -static uint pokey_divideCount[4]; -static uint pokey_sampleMax; -static uint pokey_sampleCount[2]; -static uint pokey_baseMultiplier; - -static byte rand9[0x1ff]; -static byte rand17[0x1ffff]; -static uint r9; -static uint r17; -static byte SKCTL; -byte RANDOM; - -byte POT_input[8] = {228, 228, 228, 228, 228, 228, 228, 228}; -static int pot_scanline; - -static ulong random_scanline_counter; -static ulong prev_random_scanline_counter; - -static void rand_init(byte *rng, int size, int left, int right, int add) -{ - int mask = (1 << size) - 1; - int i, x = 0; - - for( i = 0; i < mask; i++ ) - { - if (size == 17) - *rng = x >> 6; /* use bits 6..13 */ - else - *rng = x; /* use bits 0..7 */ - rng++; - /* calculate next bit */ - x = ((x << left) + (x >> right) + add) & mask; - } -} - -void pokey_setSampleRate( uint rate ) { - pokey_sampleRate = rate; -} - -// ---------------------------------------------------------------------------- -// Reset -// ---------------------------------------------------------------------------- -void pokey_Reset( ) { - pot_scanline = 0; - pokey_soundCntr = 0; - - for(int index = 0; index < POKEY_POLY17_SIZE; index++) { - pokey_poly17[index] = rand( ) & 1; - } - pokey_polyAdjust = 0; - pokey_poly04Cntr = 0; - pokey_poly05Cntr = 0; - pokey_poly17Cntr = 0; - - pokey_sampleMax = ((uint)pokey_frequency << 8) / pokey_sampleRate; - - pokey_sampleCount[0] = 0; - pokey_sampleCount[1] = 0; - - pokey_poly17Size = POKEY_POLY17_SIZE; - - for(int channel = POKEY_CHANNEL1; channel <= POKEY_CHANNEL4; channel++) { - pokey_outVol[channel] = 0; - pokey_output[channel] = 0; - pokey_divideCount[channel] = 0; - pokey_divideMax[channel] = 0x7fffffffL; - pokey_audc[channel] = 0; - pokey_audf[channel] = 0; - } - - for(int i = 0; i < 8; i++) { - POT_input[i] = 228; - } - - pokey_audctl = 0; - pokey_baseMultiplier = POKEY_DIV_64; - - /* initialize the random arrays */ - rand_init(rand9, 9, 8, 1, 0x00180); - rand_init(rand17, 17,16, 1, 0x1c000); - - SKCTL = SK_RESET; - RANDOM = 0; - - r9 = 0; - r17 = 0; - random_scanline_counter = 0; - prev_random_scanline_counter = 0; -} - -/* Called prior to each frame */ -void pokey_Frame() { -} - -/* Called prior to each scanline */ -void pokey_Scanline() { - random_scanline_counter += CYCLES_PER_SCANLINE; - - if (pot_scanline < 228) - pot_scanline++; -} - -byte pokey_GetRegister(word address) { - byte data = 0; - - byte addr = address & 0x0f; - if (addr < 8) { - byte b = POT_input[addr]; - if (b <= pot_scanline) - return b; - return pot_scanline; - } - - switch (address) { - case POKEY_ALLPOT: { - byte b = 0; - for (int i = 0; i < 8; i++) - if (POT_input[addr] <= pot_scanline) - b &= ~(1 << i); /* reset bit if pot value known */ - return b; - } - case POKEY_RANDOM: - ulong curr_scanline_counter = - ( random_scanline_counter + prosystem_cycles + prosystem_extra_cycles ); - - if( SKCTL & SK_RESET ) - { - ulong adjust = ( ( curr_scanline_counter - prev_random_scanline_counter ) >> 2 ); - r9 = (uint)((adjust + r9) % 0x001ff); - r17 = (uint)((adjust + r17) % 0x1ffff); - } - else - { - r9 = 0; - r17 = 0; - } - if( pokey_audctl & POKEY_POLY9 ) - { - RANDOM = rand9[r9]; - } - else - { - RANDOM = rand17[r17]; - } - - prev_random_scanline_counter = curr_scanline_counter; - - RANDOM = RANDOM ^ 0xff; - data = RANDOM; - break; - } - - return data; -} - -// ---------------------------------------------------------------------------- -// SetRegister -// ---------------------------------------------------------------------------- -void pokey_SetRegister(word address, byte value) { - byte channelMask; - switch(address) { - case POKEY_POTGO: - if (!(SKCTL & 4)) - pot_scanline = 0; /* slow pot mode */ - return; - - case POKEY_SKCTLS: - SKCTL = value; - if (value & 4) - pot_scanline = 228; /* fast pot mode - return results immediately */ - return; - - case POKEY_AUDF1: - pokey_audf[POKEY_CHANNEL1] = value; - channelMask = 1 << POKEY_CHANNEL1; - if(pokey_audctl & POKEY_CH1_CH2) { - channelMask |= 1 << POKEY_CHANNEL2; - } - break; - - case POKEY_AUDC1: - pokey_audc[POKEY_CHANNEL1] = value; - channelMask = 1 << POKEY_CHANNEL1; - break; - - case POKEY_AUDF2: - pokey_audf[POKEY_CHANNEL2] = value; - channelMask = 1 << POKEY_CHANNEL2; - break; - - case POKEY_AUDC2: - pokey_audc[POKEY_CHANNEL2] = value; - channelMask = 1 << POKEY_CHANNEL2; - break; - - case POKEY_AUDF3: - pokey_audf[POKEY_CHANNEL3] = value; - channelMask = 1 << POKEY_CHANNEL3; - - if(pokey_audctl & POKEY_CH3_CH4) { - channelMask |= 1 << POKEY_CHANNEL4; - } - break; - - case POKEY_AUDC3: - pokey_audc[POKEY_CHANNEL3] = value; - channelMask = 1 << POKEY_CHANNEL3; - break; - - case POKEY_AUDF4: - pokey_audf[POKEY_CHANNEL4] = value; - channelMask = 1 << POKEY_CHANNEL4; - break; - - case POKEY_AUDC4: - pokey_audc[POKEY_CHANNEL4] = value; - channelMask = 1 << POKEY_CHANNEL4; - break; - - case POKEY_AUDCTL: - pokey_audctl = value; - channelMask = 15; - if(pokey_audctl & POKEY_POLY9) { - pokey_poly17Size = POKEY_POLY9_SIZE; - } - else { - pokey_poly17Size = POKEY_POLY17_SIZE; - } - if(pokey_audctl & POKEY_CLOCK_15) { - pokey_baseMultiplier = POKEY_DIV_15; - } - else { - pokey_baseMultiplier = POKEY_DIV_64; - } - break; - - default: - channelMask = 0; - break; - } - - uint newValue = 0; - - if(channelMask & (1 << POKEY_CHANNEL1)) { - if(pokey_audctl & POKEY_CH1_179) { - newValue = pokey_audf[POKEY_CHANNEL1] + 4; - } - else { - newValue = (pokey_audf[POKEY_CHANNEL1] + 1) * pokey_baseMultiplier; - } - - if(newValue != pokey_divideMax[POKEY_CHANNEL1]) { - pokey_divideMax[POKEY_CHANNEL1] = newValue; - if(pokey_divideCount[POKEY_CHANNEL1] > newValue) { - pokey_divideCount[POKEY_CHANNEL1] = 0; - } - } - } - - if(channelMask & (1 << POKEY_CHANNEL2)) { - if(pokey_audctl & POKEY_CH1_CH2) { - if(pokey_audctl & POKEY_CH1_179) { - newValue = pokey_audf[POKEY_CHANNEL2] * 256 + pokey_audf[POKEY_CHANNEL1] + 7; - } - else { - newValue = (pokey_audf[POKEY_CHANNEL2] * 256 + pokey_audf[POKEY_CHANNEL1] + 1) * pokey_baseMultiplier; - } - } - else { - newValue = (pokey_audf[POKEY_CHANNEL2] + 1) * pokey_baseMultiplier; - } - if(newValue != pokey_divideMax[POKEY_CHANNEL2]) { - pokey_divideMax[POKEY_CHANNEL2] = newValue; - if(pokey_divideCount[POKEY_CHANNEL2] > newValue) { - pokey_divideCount[POKEY_CHANNEL2] = newValue; - } - } - } - - if(channelMask & (1 << POKEY_CHANNEL3)) { - if(pokey_audctl & POKEY_CH3_179) { - newValue = pokey_audf[POKEY_CHANNEL3] + 4; - } - else { - newValue= (pokey_audf[POKEY_CHANNEL3] + 1) * pokey_baseMultiplier; - } - if(newValue!= pokey_divideMax[POKEY_CHANNEL3]) { - pokey_divideMax[POKEY_CHANNEL3] = newValue; - if(pokey_divideCount[POKEY_CHANNEL3] > newValue) { - pokey_divideCount[POKEY_CHANNEL3] = newValue; - } - } - } - - if(channelMask & (1 << POKEY_CHANNEL4)) { - if(pokey_audctl & POKEY_CH3_CH4) { - if(pokey_audctl & POKEY_CH3_179) { - newValue = pokey_audf[POKEY_CHANNEL4] * 256 + pokey_audf[POKEY_CHANNEL3] + 7; - } - else { - newValue = (pokey_audf[POKEY_CHANNEL4] * 256 + pokey_audf[POKEY_CHANNEL3] + 1) * pokey_baseMultiplier; - } - } - else { - newValue = (pokey_audf[POKEY_CHANNEL4] + 1) * pokey_baseMultiplier; - } - if(newValue != pokey_divideMax[POKEY_CHANNEL4]) { - pokey_divideMax[POKEY_CHANNEL4] = newValue; - if(pokey_divideCount[POKEY_CHANNEL4] > newValue) { - pokey_divideCount[POKEY_CHANNEL4] = newValue; - } - } - } - - for(byte channel = POKEY_CHANNEL1; channel <= POKEY_CHANNEL4; channel++) { - if(channelMask & (1 << channel)) { - if((pokey_audc[channel] & POKEY_VOLUME_ONLY) || - ((pokey_audc[channel] & POKEY_VOLUME_MASK) == 0) || - (pokey_divideMax[channel] < (pokey_sampleMax >> 8))) { -#if 1 // WII - pokey_outVol[channel] = 1; -#else - pokey_outVol[channel] = pokey_audc[channel] & POKEY_VOLUME_MASK; -#endif - pokey_divideCount[channel] = 0x7fffffff; - pokey_divideMax[channel] = 0x7fffffff; - } - } - } -} - -// ---------------------------------------------------------------------------- -// Process -// ---------------------------------------------------------------------------- -void pokey_Process(uint length) { - byte* buffer = pokey_buffer + pokey_soundCntr; -//#ifdef BIG_ENDIAN -// uint* sampleCntrPtrB = (uint*)((byte*)&pokey_sampleCount[0] + 3); -//#else - uint* sampleCntrPtrB = (uint*)((byte*)&pokey_sampleCount[0] + 1); -//#endif - uint size = length; - - while(length) { - - byte currentValue; - byte nextEvent = POKEY_SAMPLE; - uint eventMin = *sampleCntrPtrB; - - byte channel; - for(channel = POKEY_CHANNEL1; channel <= POKEY_CHANNEL4; channel++) { - if(pokey_divideCount[channel] <= eventMin) { - eventMin = pokey_divideCount[channel]; - nextEvent = channel; - } - } - - for(channel = POKEY_CHANNEL1; channel <= POKEY_CHANNEL4; channel++) { - pokey_divideCount[channel] -= eventMin; - } - - *sampleCntrPtrB -= eventMin; - pokey_polyAdjust += eventMin; - - if(nextEvent != POKEY_SAMPLE) { - pokey_poly04Cntr = (pokey_poly04Cntr + pokey_polyAdjust) % POKEY_POLY4_SIZE; - pokey_poly05Cntr = (pokey_poly05Cntr + pokey_polyAdjust) % POKEY_POLY5_SIZE; - pokey_poly17Cntr = (pokey_poly17Cntr + pokey_polyAdjust) % pokey_poly17Size; - pokey_polyAdjust = 0; - pokey_divideCount[nextEvent] += pokey_divideMax[nextEvent]; - - if((pokey_audc[nextEvent] & POKEY_NOTPOLY5) || pokey_poly05[pokey_poly05Cntr]) { - if(pokey_audc[nextEvent] & POKEY_PURE) { - pokey_output[nextEvent] = !pokey_output[nextEvent]; - } - else if (pokey_audc[nextEvent] & POKEY_POLY4) { - pokey_output[nextEvent] = pokey_poly04[pokey_poly04Cntr]; - } - else { - pokey_output[nextEvent] = pokey_poly17[pokey_poly17Cntr]; - } - } - - if(pokey_output[nextEvent]) { - pokey_outVol[nextEvent] = pokey_audc[nextEvent] & POKEY_VOLUME_MASK; - } - else { - pokey_outVol[nextEvent] = 0; - } - } - else { -//#ifdef BIG_ENDIAN -// *(pokey_sampleCount + 1) += pokey_sampleMax; -//#else - *pokey_sampleCount += pokey_sampleMax; -//#endif - currentValue = 0; - - for(channel = POKEY_CHANNEL1; channel <= POKEY_CHANNEL4; channel++) { - currentValue += pokey_outVol[channel]; - } - - currentValue = (currentValue << 2) + 8; - *buffer++ = currentValue; - length--; - } - } - - pokey_soundCntr += size; - if(pokey_soundCntr >= pokey_size) { - pokey_soundCntr = 0; - } -} - -// ---------------------------------------------------------------------------- -// Clear -// ---------------------------------------------------------------------------- -void pokey_Clear( ) { - pokey_soundCntr = 0; - memset(pokey_buffer, 0, POKEY_BUFFER_SIZE); -} diff --git a/core/ProSystem.cpp b/core/ProSystem.cpp deleted file mode 100755 index 153924a..0000000 --- a/core/ProSystem.cpp +++ /dev/null @@ -1,640 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2003, 2004 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// ProSystem.cpp -// ---------------------------------------------------------------------------- -#include "ProSystem.h" -#define PRO_SYSTEM_STATE_HEADER "PRO-SYSTEM STATE" -#define PRO_SYSTEM_SOURCE "ProSystem.cpp" - -bool prosystem_active = false; -bool prosystem_paused = false; -word prosystem_frequency = 60; -byte prosystem_frame = 0; -word prosystem_scanlines = 262; -uint prosystem_cycles = 0; -int lightgun_scanline = 0; -float lightgun_cycle = 0; - -// Whether the last CPU operation resulted in a half cycle (need to take it -// into consideration) -extern bool half_cycle; - -// ---------------------------------------------------------------------------- -// Reset -// ---------------------------------------------------------------------------- -void prosystem_Reset( ) { - if(cartridge_IsLoaded( )) { - prosystem_paused = false; - prosystem_frame = 0; - sally_Reset( ); - region_Reset( ); - tia_Clear( ); - tia_Reset( ); - pokey_Clear( ); - pokey_Reset( ); - xm_Reset( ); - memory_Reset( ); - maria_Clear( ); - maria_Reset( ); - riot_Reset( ); - if(bios_enabled) { - bios_Store( ); - } - else { - cartridge_Store( ); - } - prosystem_cycles = sally_ExecuteRES( ); - prosystem_active = true; - } -} - -/* - * Strobe based on the current lightgun location - */ -static void prosystem_FireLightGun() -{ - if( ( ( maria_scanline >= lightgun_scanline ) && - ( maria_scanline <= ( lightgun_scanline + 3 ) ) ) && - ( prosystem_cycles >= ((int)lightgun_cycle ) - 1 ) ) - { - memory_ram[INPT4] &= 0x7f; - } - else - { - memory_ram[INPT4] |= 0x80; - } -} - -uint prosystem_extra_cycles = 0; -// ---------------------------------------------------------------------------- -// ExecuteFrame -// ---------------------------------------------------------------------------- -void prosystem_ExecuteFrame(const byte* input) { - // Is WSYNC enabled for the current frame? - bool wsync = !(cartridge_flags & CARTRIDGE_WSYNC_MASK); - - // Is Maria cycle stealing enabled for the current frame? - bool cycle_stealing = !(cartridge_flags & CARTRIDGE_CYCLE_STEALING_MASK); - - // Is the lightgun enabled for the current frame? - bool lightgun = ((cartridge_controller[0] & CARTRIDGE_CONTROLLER_LIGHTGUN) && (memory_ram[CTRL] & 96) != 64); - - riot_SetInput(input); - - prosystem_extra_cycles = 0; - - if(cartridge_pokey || cartridge_xm) pokey_Frame(); - - for(maria_scanline = 1; maria_scanline <= prosystem_scanlines; maria_scanline++) { - if(maria_scanline == maria_displayArea.top) { - memory_ram[MSTAT] = 0; - } - else if(maria_scanline == maria_displayArea.bottom) { - memory_ram[MSTAT] = 128; - } - - // Was a WSYNC performed withing the current scanline? - bool wsync_scanline = false; - - uint cycles = 0; - - if(!cycle_stealing || (memory_ram[CTRL] & 96 ) != 64) { - // Exact cycle counts when Maria is disabled - prosystem_cycles %= CYCLES_PER_SCANLINE; - prosystem_extra_cycles = 0; - } - else - { - prosystem_extra_cycles = (prosystem_cycles % CYCLES_PER_SCANLINE); - - // Some fudge for Maria cycles. Unfortunately Maria cycle counting - // isn't exact (This adds some extra cycles). - prosystem_cycles = 0; - } - - // If lightgun is enabled, check to see if it should be fired - if(lightgun) prosystem_FireLightGun(); - - while(prosystem_cycles < cartridge_hblank) { - cycles = sally_ExecuteInstruction( ); - prosystem_cycles += (cycles << 2); - if(half_cycle) prosystem_cycles += 2; - - if(riot_timing) { - riot_UpdateTimer(cycles); - } - - // If lightgun is enabled, check to see if it should be fired - if(lightgun) prosystem_FireLightGun(); - - if(memory_ram[WSYNC] && wsync) { - memory_ram[WSYNC] = false; - wsync_scanline = true; - break; - } - } - - cycles = maria_RenderScanline( ); - - if(cycle_stealing) { - prosystem_cycles += cycles; - - if(riot_timing) { - riot_UpdateTimer(cycles >> 2); - } - } - - while(!wsync_scanline && prosystem_cycles < CYCLES_PER_SCANLINE) { - cycles = sally_ExecuteInstruction( ); - prosystem_cycles += (cycles << 2); - if(half_cycle) prosystem_cycles += 2; - - // If lightgun is enabled, check to see if it should be fired - if(lightgun) prosystem_FireLightGun(); - - if(riot_timing) { - riot_UpdateTimer(cycles); - } - - if(memory_ram[WSYNC] && wsync) { - memory_ram[WSYNC] = false; - wsync_scanline = true; - break; - } - } - - // If a WSYNC was performed and the current cycle count is less than - // the cycles per scanline, add those cycles to current timers. - if(wsync_scanline && prosystem_cycles < CYCLES_PER_SCANLINE) { - if(riot_timing) - { - riot_UpdateTimer((CYCLES_PER_SCANLINE - prosystem_cycles) >> 2); - } - prosystem_cycles = CYCLES_PER_SCANLINE; - } - - // If lightgun is enabled, check to see if it should be fired - if(lightgun) prosystem_FireLightGun(); - - tia_Process(2); - if(cartridge_pokey || cartridge_xm) { - pokey_Process(2); - } - - if(cartridge_pokey || cartridge_xm) pokey_Scanline(); - } - - prosystem_frame++; - if(prosystem_frame >= prosystem_frequency) { - prosystem_frame = 0; - } -} - -// ---------------------------------------------------------------------------- -// Save -// ---------------------------------------------------------------------------- -bool prosystem_Save(std::string filename, bool compress) { - if(filename.empty( ) || filename.length( ) == 0) { - logger_LogError("Filename is invalid.", PRO_SYSTEM_SOURCE); - return false; - } - - logger_LogInfo("Saving game state to file " + filename + ".", PRO_SYSTEM_SOURCE); - - byte loc_buffer[33000 + XM_RAM_SIZE + 4] = {0}; - - uint size = 0; - - uint index; - for(index = 0; index < 16; index++) { - loc_buffer[size + index] = PRO_SYSTEM_STATE_HEADER[index]; - } - size += 16; - - loc_buffer[size++] = 1; - for(index = 0; index < 4; index++) { - loc_buffer[size + index] = 0; - } - size += 4; - - for(index = 0; index < 32; index++) { - loc_buffer[size + index] = cartridge_digest[index]; - } - size += 32; - - loc_buffer[size++] = sally_a; - loc_buffer[size++] = sally_x; - loc_buffer[size++] = sally_y; - loc_buffer[size++] = sally_p; - loc_buffer[size++] = sally_s; - loc_buffer[size++] = sally_pc.b.l; - loc_buffer[size++] = sally_pc.b.h; - loc_buffer[size++] = cartridge_bank; - - for(index = 0; index < 16384; index++) { - loc_buffer[size + index] = memory_ram[index]; - } - size += 16384; - - if(cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM) { - for(index = 0; index < 16384; index++) { - loc_buffer[size + index] = memory_ram[16384 + index]; - } - size += 16384; - } - - // RIOT state - loc_buffer[size++] = riot_dra; - loc_buffer[size++] = riot_drb; - loc_buffer[size++] = riot_timing; - loc_buffer[size++] = ( 0xff & ( riot_timer >> 8 ) ); - loc_buffer[size++] = ( 0xff & riot_timer ); - loc_buffer[size++] = riot_intervals; - loc_buffer[size++] = ( 0xff & ( riot_clocks >> 8 ) ); - loc_buffer[size++] = ( 0xff & riot_clocks ); - - // XM (if applicable) - if (cartridge_xm) { - loc_buffer[size++] = xm_reg; - loc_buffer[size++] = xm_bank; - loc_buffer[size++] = xm_pokey_enabled; - loc_buffer[size++] = xm_mem_enabled; - - for (index = 0; index < XM_RAM_SIZE; index++) { - loc_buffer[size + index] = xm_ram[index]; - } - size += XM_RAM_SIZE; - } - - FILE* file = fopen(filename.c_str( ), "wb"); - if(file == NULL) { - logger_LogError("Failed to open the file " + filename + " for writing.", PRO_SYSTEM_SOURCE); - return false; - } - - if(fwrite(loc_buffer, 1, size, file) != size) { - fclose(file); - logger_LogError("Failed to write the save state data to the file " + filename + ".", PRO_SYSTEM_SOURCE); - return false; - } - - fflush(file); - fclose(file); - - return true; -} - -bool prosystem_Save_buffer(byte *buffer) -{ - uint size = 0; - uint index; - - for(index = 0; index < 16; index++) { - buffer[size + index] = PRO_SYSTEM_STATE_HEADER[index]; - } - size += 16; - - buffer[size++] = 1; - for(index = 0; index < 4; index++) { - buffer[size + index] = 0; - } - size += 4; - - for(index = 0; index < 32; index++) { - buffer[size + index] = cartridge_digest[index]; - } - size += 32; - - buffer[size++] = sally_a; - buffer[size++] = sally_x; - buffer[size++] = sally_y; - buffer[size++] = sally_p; - buffer[size++] = sally_s; - buffer[size++] = sally_pc.b.l; - buffer[size++] = sally_pc.b.h; - buffer[size++] = cartridge_bank; - - for(index = 0; index < 16384; index++) { - buffer[size + index] = memory_ram[index]; - } - size += 16384; - - if(cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM) { - for(index = 0; index < 16384; index++) { - buffer[size + index] = memory_ram[16384 + index]; - } - size += 16384; - } - - // RIOT state - buffer[size++] = riot_dra; - buffer[size++] = riot_drb; - buffer[size++] = riot_timing; - buffer[size++] = ( 0xff & ( riot_timer >> 8 ) ); - buffer[size++] = ( 0xff & riot_timer ); - buffer[size++] = riot_intervals; - buffer[size++] = ( 0xff & ( riot_clocks >> 8 ) ); - buffer[size++] = ( 0xff & riot_clocks ); - - // XM (if applicable) - if (cartridge_xm) { - buffer[size++] = xm_reg; - buffer[size++] = xm_bank; - buffer[size++] = xm_pokey_enabled; - buffer[size++] = xm_mem_enabled; - - for (index = 0; index < XM_RAM_SIZE; index++) { - buffer[size + index] = xm_ram[index]; - } - size += XM_RAM_SIZE; - } - - return true; -} - -// ---------------------------------------------------------------------------- -// Load -// ---------------------------------------------------------------------------- -bool prosystem_Load(const std::string filename) { - if(filename.empty( ) || filename.length( ) == 0) { - logger_LogError("Filename is invalid.", PRO_SYSTEM_SOURCE); - return false; - } - - logger_LogInfo("Loading game state from file " + filename + ".", PRO_SYSTEM_SOURCE); - - byte loc_buffer[33000 + XM_RAM_SIZE + 4] = {0}; - - uint size = archive_GetUncompressedFileSize(filename); - if(size == 0) { - FILE* file = fopen(filename.c_str( ), "rb"); - if(file == NULL) { - logger_LogError("Failed to open the file " + filename + " for reading.", PRO_SYSTEM_SOURCE); - return false; - } - - if(fseek(file, 0L, SEEK_END)) { - fclose(file); - logger_LogError("Failed to find the end of the file.", PRO_SYSTEM_SOURCE); - return false; - } - - size = ftell(file); - if(fseek(file, 0L, SEEK_SET)) { - fclose(file); - logger_LogError("Failed to find the size of the file.", PRO_SYSTEM_SOURCE); - return false; - } - - if( size != 16445 && size != 32829 && /* no RIOT */ - size != 16453 && size != 32837 && /* with RIOT */ - size != (16453 + 4 + XM_RAM_SIZE) && /* XM without supercart ram */ - size != (32837 + 4 + XM_RAM_SIZE)) /* XM with supercart ram */ - { - fclose(file); - logger_LogError("Save state file has an invalid size.", PRO_SYSTEM_SOURCE); - return false; - } - - if(fread(loc_buffer, 1, size, file) != size && ferror(file)) { - fclose(file); - logger_LogError("Failed to read the file data.", PRO_SYSTEM_SOURCE); - return false; - } - fclose(file); - } - else { - logger_LogError("Save state file has an invalid size.", PRO_SYSTEM_SOURCE); - return false; - } - - uint offset = 0; - uint index; - for(index = 0; index < 16; index++) { - if(loc_buffer[offset + index] != PRO_SYSTEM_STATE_HEADER[index]) { - logger_LogError("File is not a valid ProSystem save state.", PRO_SYSTEM_SOURCE); - return false; - } - } - offset += 16; - byte version = loc_buffer[offset++]; - - uint date = 0; - for(index = 0; index < 4; index++) { - } - offset += 4; - - prosystem_Reset( ); - - char digest[33] = {0}; - for(index = 0; index < 32; index++) { - digest[index] = loc_buffer[offset + index]; - } - offset += 32; - if(cartridge_digest != std::string(digest)) { - logger_LogError("Load state digest [" + std::string(digest) + "] does not match loaded cartridge digest [" + cartridge_digest + "].", PRO_SYSTEM_SOURCE); - return false; - } - - sally_a = loc_buffer[offset++]; - sally_x = loc_buffer[offset++]; - sally_y = loc_buffer[offset++]; - sally_p = loc_buffer[offset++]; - sally_s = loc_buffer[offset++]; - sally_pc.b.l = loc_buffer[offset++]; - sally_pc.b.h = loc_buffer[offset++]; - - cartridge_StoreBank(loc_buffer[offset++]); - - for(index = 0; index < 16384; index++) { - memory_ram[index] = loc_buffer[offset + index]; - } - offset += 16384; - - if(cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM) { - if (size != 32829 && /* no RIOT */ - size != 32837 && /* with RIOT */ - size != (32837 + 4 + XM_RAM_SIZE)) /* XM */ { - logger_LogError("Save state file has an invalid size.", PRO_SYSTEM_SOURCE); - return false; - } - for(index = 0; index < 16384; index++) { - memory_ram[16384 + index] = loc_buffer[offset + index]; - } - offset += 16384; - } - - if (size == 16453 || /* no supercart ram */ - size == 32837 || /* supercart ram */ - size == (16453 + 4 + XM_RAM_SIZE) || /* xm, no supercart ram */ - size == (32837 + 4 + XM_RAM_SIZE)) /* xm, supercart ram */ { - // RIOT state - riot_dra = loc_buffer[offset++]; - riot_drb = loc_buffer[offset++]; - riot_timing = loc_buffer[offset++]; - riot_timer = ( loc_buffer[offset++] << 8 ); - riot_timer |= loc_buffer[offset++]; - riot_intervals = loc_buffer[offset++]; - riot_clocks = ( loc_buffer[offset++] << 8 ); - riot_clocks |= loc_buffer[offset++]; - } - - // XM (if applicable) - if (cartridge_xm) { - if ((size != (16453 + 4 + XM_RAM_SIZE)) && - (size != (32837 + 4 + XM_RAM_SIZE))) { - logger_LogError("Save state file has an invalid size.", PRO_SYSTEM_SOURCE); - return false; - } - xm_reg = loc_buffer[offset++]; - xm_bank = loc_buffer[offset++]; - xm_pokey_enabled = loc_buffer[offset++]; - xm_mem_enabled = loc_buffer[offset++]; - - for (index = 0; index < XM_RAM_SIZE; index++) { - xm_ram[index] = loc_buffer[offset++]; - } - } - - return true; -} - -bool prosystem_Load_buffer(const byte *buffer) -{ - uint size = cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM ? 32837 : 16453; - if(cartridge_xm) { - size += 4 + XM_RAM_SIZE; - } - uint offset = 0; - uint index; - - for(index = 0; index < 16; index++) { - if(buffer[offset + index] != PRO_SYSTEM_STATE_HEADER[index]) { - logger_LogError("File is not a valid ProSystem save state.", PRO_SYSTEM_SOURCE); - return false; - } - } - offset += 16; - - byte version = buffer[offset++]; - //uint date = 0; - - offset += 4; - - //prosystem_Reset(); // TODO doesn't seem necessary but needs investigation - - char digest[33] = {0}; - for(index = 0; index < 32; index++) { - digest[index] = buffer[offset + index]; - } - offset += 32; - if(cartridge_digest != std::string(digest)) { - logger_LogError("Load state digest [" + std::string(digest) + "] does not match loaded cartridge digest [" + cartridge_digest + "].", PRO_SYSTEM_SOURCE); - return false; - } - - sally_a = buffer[offset++]; - sally_x = buffer[offset++]; - sally_y = buffer[offset++]; - sally_p = buffer[offset++]; - sally_s = buffer[offset++]; - sally_pc.b.l = buffer[offset++]; - sally_pc.b.h = buffer[offset++]; - - cartridge_StoreBank(buffer[offset++]); - - for(index = 0; index < 16384; index++) { - memory_ram[index] = buffer[offset + index]; - } - offset += 16384; - - if(cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM) { - if (size != 32829 && /* no RIOT */ - size != 32837 && /* with RIOT */ - size != (32837 + 4 + XM_RAM_SIZE)) /* XM */ { - logger_LogError("Save state file has an invalid size.", PRO_SYSTEM_SOURCE); - return false; - } - for(index = 0; index < 16384; index++) { - memory_ram[16384 + index] = buffer[offset + index]; - } - offset += 16384; - } - - if (size == 16453 || /* no supercart ram */ - size == 32837 || /* supercart ram */ - size == (16453 + 4 + XM_RAM_SIZE) || /* xm, no supercart ram */ - size == (32837 + 4 + XM_RAM_SIZE)) /* xm, supercart ram */ { - // RIOT state - riot_dra = buffer[offset++]; - riot_drb = buffer[offset++]; - riot_timing = buffer[offset++]; - riot_timer = ( buffer[offset++] << 8 ); - riot_timer |= buffer[offset++]; - riot_intervals = buffer[offset++]; - riot_clocks = ( buffer[offset++] << 8 ); - riot_clocks |= buffer[offset++]; - } - - // XM (if applicable) - if (cartridge_xm) { - if ((size != (16453 + 4 + XM_RAM_SIZE)) && - (size != (32837 + 4 + XM_RAM_SIZE))) { - logger_LogError("Save state file has an invalid size.", PRO_SYSTEM_SOURCE); - return false; - } - xm_reg = buffer[offset++]; - xm_bank = buffer[offset++]; - xm_pokey_enabled = buffer[offset++]; - xm_mem_enabled = buffer[offset++]; - - for (index = 0; index < XM_RAM_SIZE; index++) { - xm_ram[index] = buffer[offset++]; - } - } - - return true; -} - -// ---------------------------------------------------------------------------- -// Pause -// ---------------------------------------------------------------------------- -void prosystem_Pause(bool pause) { - if(prosystem_active) { - prosystem_paused = pause; - } -} - -// ---------------------------------------------------------------------------- -// Close -// ---------------------------------------------------------------------------- -void prosystem_Close( ) { - prosystem_active = false; - prosystem_paused = false; - cartridge_Release( ); - maria_Reset( ); - maria_Clear( ); - memory_Reset( ); - tia_Reset( ); - tia_Clear( ); -} diff --git a/core/Rect.h b/core/Rect.h deleted file mode 100755 index af47e44..0000000 --- a/core/Rect.h +++ /dev/null @@ -1,52 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Rect.h -// ---------------------------------------------------------------------------- -#ifndef RECT_H -#define RECT_H - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -struct Rects { - uint left; - uint top; - uint right; - uint bottom; - - uint GetArea( ) { - return GetLength( ) * GetHeight( ); - } - - uint GetLength( ) { - return (right - left) + 1; - } - - uint GetHeight( ) { - return (bottom - top) + 1; - } -}; - -typedef Rects rect; -#endif \ No newline at end of file diff --git a/core/Region.cpp b/core/Region.cpp deleted file mode 100755 index 93e8b9f..0000000 --- a/core/Region.cpp +++ /dev/null @@ -1,204 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Region.h -// ---------------------------------------------------------------------------- -#include "Region.h" - -byte region_type = REGION_AUTO; - -static const rect REGION_DISPLAY_AREA_NTSC = {0, 16, 319, 258}; -static const rect REGION_VISIBLE_AREA_NTSC = {0, 26, 319, 250}; -static const byte REGION_FREQUENCY_NTSC = 60; -static const word REGION_SCANLINES_NTSC = 262; - -static const rect REGION_DISPLAY_AREA_PAL = {0, 16, 319, 308}; -static const rect REGION_VISIBLE_AREA_PAL = {0, 26, 319, 297}; -static const byte REGION_FREQUENCY_PAL = 50; -static const word REGION_SCANLINES_PAL = 312; - -// ---------------------------------------------------------------------------- -// PALETTE NTSC -// ---------------------------------------------------------------------------- -static const byte REGION_PALETTE_NTSC[ ] = { -0x00,0x00,0x00,0x25,0x25,0x25,0x34,0x34,0x34,0x4F,0x4F,0x4F, -0x5B,0x5B,0x5B,0x69,0x69,0x69,0x7B,0x7B,0x7B,0x8A,0x8A,0x8A, -0xA7,0xA7,0xA7,0xB9,0xB9,0xB9,0xC5,0xC5,0xC5,0xD0,0xD0,0xD0, -0xD7,0xD7,0xD7,0xE1,0xE1,0xE1,0xF4,0xF4,0xF4,0xFF,0xFF,0xFF, -0x4C,0x32,0x00,0x62,0x3A,0x00,0x7B,0x4A,0x00,0x9A,0x60,0x00, -0xB5,0x74,0x00,0xCC,0x85,0x00,0xE7,0x9E,0x08,0xF7,0xAF,0x10, -0xFF,0xC3,0x18,0xFF,0xD0,0x20,0xFF,0xD8,0x28,0xFF,0xDF,0x30, -0xFF,0xE6,0x3B,0xFF,0xF4,0x40,0xFF,0xFA,0x4B,0xFF,0xFF,0x50, -0x99,0x25,0x00,0xAA,0x25,0x00,0xB4,0x25,0x00,0xD3,0x30,0x00, -0xDD,0x48,0x02,0xE2,0x50,0x09,0xF4,0x67,0x00,0xF4,0x75,0x10, -0xFF,0x9E,0x10,0xFF,0xAC,0x20,0xFF,0xBA,0x3A,0xFF,0xBF,0x50, -0xFF,0xC6,0x6D,0xFF,0xD5,0x80,0xFF,0xE4,0x90,0xFF,0xE6,0x99, -0x98,0x0C,0x0C,0x99,0x0C,0x0C,0xC2,0x13,0x00,0xD3,0x13,0x00, -0xE2,0x35,0x00,0xE3,0x40,0x00,0xE4,0x40,0x20,0xE5,0x52,0x30, -0xFD,0x78,0x54,0xFF,0x8A,0x6A,0xFF,0x98,0x7C,0xFF,0xA4,0x8B, -0xFF,0xB3,0x9E,0xFF,0xC2,0xB2,0xFF,0xD0,0xBA,0xFF,0xD7,0xC0, -0x99,0x00,0x00,0xA9,0x00,0x00,0xC2,0x04,0x00,0xD3,0x04,0x00, -0xDA,0x04,0x00,0xDB,0x08,0x00,0xE4,0x20,0x20,0xF6,0x40,0x40, -0xFB,0x70,0x70,0xFB,0x7E,0x7E,0xFB,0x8F,0x8F,0xFF,0x9F,0x9F, -0xFF,0xAB,0xAB,0xFF,0xB9,0xB9,0xFF,0xC9,0xC9,0xFF,0xCF,0xCF, -0x7E,0x00,0x50,0x80,0x00,0x50,0x80,0x00,0x5F,0x95,0x0B,0x74, -0xAA,0x22,0x88,0xBB,0x2F,0x9A,0xCE,0x3F,0xAD,0xD7,0x5A,0xB6, -0xE4,0x67,0xC3,0xEF,0x72,0xCE,0xFB,0x7E,0xDA,0xFF,0x8D,0xE1, -0xFF,0x9D,0xE5,0xFF,0xA5,0xE7,0xFF,0xAF,0xEA,0xFF,0xB8,0xEC, -0x48,0x00,0x6C,0x5C,0x04,0x88,0x65,0x0D,0x90,0x7B,0x23,0xA7, -0x93,0x3B,0xBF,0x9D,0x45,0xC9,0xA7,0x4F,0xD3,0xB2,0x5A,0xDE, -0xBD,0x65,0xE9,0xC5,0x6D,0xF1,0xCE,0x76,0xFA,0xD5,0x83,0xFF, -0xDA,0x90,0xFF,0xDE,0x9C,0xFF,0xE2,0xA9,0xFF,0xE6,0xB6,0xFF, -0x1B,0x00,0x70,0x22,0x1B,0x8D,0x37,0x30,0xA2,0x48,0x41,0xB3, -0x59,0x52,0xC4,0x63,0x5C,0xCE,0x6F,0x68,0xDA,0x7D,0x76,0xE8, -0x87,0x80,0xF8,0x93,0x8C,0xFF,0x9D,0x97,0xFF,0xA8,0xA3,0xFF, -0xB3,0xAF,0xFF,0xBC,0xB8,0xFF,0xC4,0xC1,0xFF,0xDA,0xD1,0xFF, -0x00,0x0D,0x7F,0x00,0x12,0xA7,0x00,0x18,0xC0,0x0A,0x2B,0xD1, -0x1B,0x4A,0xE3,0x2F,0x58,0xF0,0x37,0x68,0xFF,0x49,0x79,0xFF, -0x5B,0x85,0xFF,0x6D,0x96,0xFF,0x7F,0xA3,0xFF,0x8C,0xAD,0xFF, -0x96,0xB4,0xFF,0xA8,0xC0,0xFF,0xB7,0xCB,0xFF,0xC6,0xD6,0xFF, -0x00,0x29,0x5A,0x00,0x38,0x76,0x00,0x48,0x92,0x00,0x5C,0xAC, -0x00,0x71,0xC6,0x00,0x86,0xD0,0x0A,0x9B,0xDF,0x1A,0xA8,0xEC, -0x2B,0xB6,0xFF,0x3F,0xC2,0xFF,0x45,0xCB,0xFF,0x59,0xD3,0xFF, -0x7F,0xDA,0xFF,0x8F,0xDE,0xFF,0xA0,0xE2,0xFF,0xB0,0xEB,0xFF, -0x00,0x38,0x39,0x00,0x3C,0x48,0x00,0x3D,0x5B,0x02,0x66,0x7F, -0x03,0x73,0x83,0x00,0x9C,0xAA,0x00,0xA1,0xBB,0x01,0xA4,0xCC, -0x03,0xBB,0xFF,0x05,0xDA,0xE2,0x18,0xE5,0xFF,0x34,0xEA,0xFF, -0x49,0xEF,0xFF,0x66,0xF2,0xFF,0x84,0xF4,0xFF,0x9E,0xF9,0xFF, -0x00,0x4A,0x00,0x00,0x5D,0x00,0x00,0x70,0x00,0x00,0x8B,0x00, -0x00,0xA9,0x00,0x00,0xBB,0x05,0x00,0xBD,0x00,0x02,0xD0,0x05, -0x1A,0xD5,0x40,0x5A,0xF1,0x77,0x82,0xEF,0xA7,0x84,0xED,0xD1, -0x89,0xFF,0xED,0x7D,0xFF,0xFF,0x93,0xFF,0xFF,0x9B,0xFF,0xFF, -0x22,0x4A,0x03,0x27,0x53,0x04,0x30,0x64,0x05,0x3C,0x77,0x0C, -0x45,0x8C,0x11,0x5A,0xA5,0x13,0x1B,0xD2,0x09,0x1F,0xDD,0x00, -0x3D,0xCD,0x2D,0x3D,0xCD,0x30,0x58,0xCC,0x40,0x60,0xD3,0x50, -0xA2,0xEC,0x55,0xB3,0xF2,0x4A,0xBB,0xF6,0x5D,0xC4,0xF8,0x70, -0x2E,0x3F,0x0C,0x36,0x4A,0x0F,0x40,0x56,0x15,0x46,0x5F,0x17, -0x57,0x77,0x1A,0x65,0x85,0x1C,0x74,0x93,0x1D,0x8F,0xA5,0x25, -0xAD,0xB7,0x2C,0xBC,0xC7,0x30,0xC9,0xD5,0x33,0xD4,0xE0,0x3B, -0xE0,0xEC,0x42,0xEA,0xF6,0x45,0xF0,0xFD,0x47,0xF4,0xFF,0x6F, -0x55,0x24,0x00,0x5A,0x2C,0x00,0x6C,0x3B,0x00,0x79,0x4B,0x00, -0xB9,0x75,0x00,0xBB,0x85,0x00,0xC1,0xA1,0x20,0xD0,0xB0,0x2F, -0xDE,0xBE,0x3F,0xE6,0xC6,0x45,0xED,0xCD,0x57,0xF5,0xDB,0x62, -0xFB,0xE5,0x69,0xFC,0xEE,0x6F,0xFD,0xF3,0x77,0xFD,0xF3,0x7F, -0x5C,0x27,0x00,0x5C,0x2F,0x00,0x71,0x3B,0x00,0x7B,0x48,0x00, -0xB9,0x68,0x20,0xBB,0x72,0x20,0xC5,0x86,0x29,0xD7,0x96,0x33, -0xE6,0xA4,0x40,0xF4,0xB1,0x4B,0xFD,0xC1,0x58,0xFF,0xCC,0x55, -0xFF,0xD4,0x61,0xFF,0xDD,0x69,0xFF,0xE6,0x79,0xFF,0xEA,0x98 -}; - -// -------------------------------------------------------------------------------------- -// PALETTE PAL -// -------------------------------------------------------------------------------------- -static const byte REGION_PALETTE_PAL[ ] = { - 0x00,0x00,0x00,0x1c,0x1c,0x1c,0x39,0x39,0x39,0x59,0x59,0x59, - 0x79,0x79,0x79,0x92,0x92,0x92,0xab,0xab,0xab,0xbc,0xbc,0xbc, - 0xcd,0xcd,0xcd,0xd9,0xd9,0xd9,0xe6,0xe6,0xe6,0xec,0xec,0xec, - 0xf2,0xf2,0xf2,0xf8,0xf8,0xf8,0xff,0xff,0xff,0xff,0xff,0xff, - 0x26,0x30,0x01,0x24,0x38,0x03,0x23,0x40,0x05,0x51,0x54,0x1b, - 0x80,0x69,0x31,0x97,0x81,0x35,0xaf,0x99,0x3a,0xc2,0xa7,0x3e, - 0xd5,0xb5,0x43,0xdb,0xc0,0x3d,0xe1,0xcb,0x38,0xe2,0xd8,0x36, - 0xe3,0xe5,0x34,0xef,0xf2,0x58,0xfb,0xff,0x7d,0xfb,0xff,0x7d, - 0x39,0x17,0x01,0x5e,0x23,0x04,0x83,0x30,0x08,0xa5,0x47,0x16, - 0xc8,0x5f,0x24,0xe3,0x78,0x20,0xff,0x91,0x1d,0xff,0xab,0x1d, - 0xff,0xc5,0x1d,0xff,0xce,0x34,0xff,0xd8,0x4c,0xff,0xe6,0x51, - 0xff,0xf4,0x56,0xff,0xf9,0x77,0xff,0xff,0x98,0xff,0xff,0x98, - 0x45,0x19,0x04,0x72,0x1e,0x11,0x9f,0x24,0x1e,0xb3,0x3a,0x20, - 0xc8,0x51,0x22,0xe3,0x69,0x20,0xff,0x81,0x1e,0xff,0x8c,0x25, - 0xff,0x98,0x2c,0xff,0xae,0x38,0xff,0xc5,0x45,0xff,0xc5,0x59, - 0xff,0xc6,0x6d,0xff,0xd5,0x87,0xff,0xe4,0xa1,0xff,0xe4,0xa1, - 0x4a,0x17,0x04,0x7e,0x1a,0x0d,0xb2,0x1d,0x17,0xc8,0x21,0x19, - 0xdf,0x25,0x1c,0xec,0x3b,0x38,0xfa,0x52,0x55,0xfc,0x61,0x61, - 0xff,0x70,0x6e,0xff,0x7f,0x7e,0xff,0x8f,0x8f,0xff,0x9d,0x9e, - 0xff,0xab,0xad,0xff,0xb9,0xbd,0xff,0xc7,0xce,0xff,0xc7,0xce, - 0x05,0x05,0x68,0x3b,0x13,0x6d,0x71,0x22,0x72,0x8b,0x2a,0x8c, - 0xa5,0x32,0xa6,0xb9,0x38,0xba,0xcd,0x3e,0xcf,0xdb,0x47,0xdd, - 0xea,0x51,0xeb,0xf4,0x5f,0xf5,0xfe,0x6d,0xff,0xfe,0x7a,0xfd, - 0xff,0x87,0xfb,0xff,0x95,0xfd,0xff,0xa4,0xff,0xff,0xa4,0xff, - 0x28,0x04,0x79,0x40,0x09,0x84,0x59,0x0f,0x90,0x70,0x24,0x9d, - 0x88,0x39,0xaa,0xa4,0x41,0xc3,0xc0,0x4a,0xdc,0xd0,0x54,0xed, - 0xe0,0x5e,0xff,0xe9,0x6d,0xff,0xf2,0x7c,0xff,0xf8,0x8a,0xff, - 0xff,0x98,0xff,0xfe,0xa1,0xff,0xfe,0xab,0xff,0xfe,0xab,0xff, - 0x35,0x08,0x8a,0x42,0x0a,0xad,0x50,0x0c,0xd0,0x64,0x28,0xd0, - 0x79,0x45,0xd0,0x8d,0x4b,0xd4,0xa2,0x51,0xd9,0xb0,0x58,0xec, - 0xbe,0x60,0xff,0xc5,0x6b,0xff,0xcc,0x77,0xff,0xd1,0x83,0xff, - 0xd7,0x90,0xff,0xdb,0x9d,0xff,0xdf,0xaa,0xff,0xdf,0xaa,0xff, - 0x05,0x1e,0x81,0x06,0x26,0xa5,0x08,0x2f,0xca,0x26,0x3d,0xd4, - 0x44,0x4c,0xde,0x4f,0x5a,0xee,0x5a,0x68,0xff,0x65,0x75,0xff, - 0x71,0x83,0xff,0x80,0x91,0xff,0x90,0xa0,0xff,0x97,0xa9,0xff, - 0x9f,0xb2,0xff,0xaf,0xbe,0xff,0xc0,0xcb,0xff,0xc0,0xcb,0xff, - 0x05,0x1e,0x81,0x06,0x26,0xa5,0x08,0x2f,0xca,0x26,0x3d,0xd4, - 0x44,0x4c,0xde,0x4f,0x5a,0xee,0x5a,0x68,0xff,0x65,0x75,0xff, - 0x71,0x83,0xff,0x80,0x91,0xff,0x90,0xa0,0xff,0x97,0xa9,0xff, - 0x9f,0xb2,0xff,0xaf,0xbe,0xff,0xc0,0xcb,0xff,0xc0,0xcb,0xff, - 0x0c,0x04,0x8b,0x22,0x18,0xa0,0x38,0x2d,0xb5,0x48,0x3e,0xc7, - 0x58,0x4f,0xda,0x61,0x59,0xec,0x6b,0x64,0xff,0x7a,0x74,0xff, - 0x8a,0x84,0xff,0x91,0x8e,0xff,0x99,0x98,0xff,0xa5,0xa3,0xff, - 0xb1,0xae,0xff,0xb8,0xb8,0xff,0xc0,0xc2,0xff,0xc0,0xc2,0xff, - 0x1d,0x29,0x5a,0x1d,0x38,0x76,0x1d,0x48,0x92,0x1c,0x5c,0xac, - 0x1c,0x71,0xc6,0x32,0x86,0xcf,0x48,0x9b,0xd9,0x4e,0xa8,0xec, - 0x55,0xb6,0xff,0x70,0xc7,0xff,0x8c,0xd8,0xff,0x93,0xdb,0xff, - 0x9b,0xdf,0xff,0xaf,0xe4,0xff,0xc3,0xe9,0xff,0xc3,0xe9,0xff, - 0x2f,0x43,0x02,0x39,0x52,0x02,0x44,0x61,0x03,0x41,0x7a,0x12, - 0x3e,0x94,0x21,0x4a,0x9f,0x2e,0x57,0xab,0x3b,0x5c,0xbd,0x55, - 0x61,0xd0,0x70,0x69,0xe2,0x7a,0x72,0xf5,0x84,0x7c,0xfa,0x8d, - 0x87,0xff,0x97,0x9a,0xff,0xa6,0xad,0xff,0xb6,0xad,0xff,0xb6, - 0x0a,0x41,0x08,0x0d,0x54,0x0a,0x10,0x68,0x0d,0x13,0x7d,0x0f, - 0x16,0x92,0x12,0x19,0xa5,0x14,0x1c,0xb9,0x17,0x1e,0xc9,0x19, - 0x21,0xd9,0x1b,0x47,0xe4,0x2d,0x6e,0xf0,0x40,0x78,0xf7,0x4d, - 0x83,0xff,0x5b,0x9a,0xff,0x7a,0xb2,0xff,0x9a,0xb2,0xff,0x9a, - 0x04,0x41,0x0b,0x05,0x53,0x0e,0x06,0x66,0x11,0x07,0x77,0x14, - 0x08,0x88,0x17,0x09,0x9b,0x1a,0x0b,0xaf,0x1d,0x48,0xc4,0x1f, - 0x86,0xd9,0x22,0x8f,0xe9,0x24,0x99,0xf9,0x27,0xa8,0xfc,0x41, - 0xb7,0xff,0x5b,0xc9,0xff,0x6e,0xdc,0xff,0x81,0xdc,0xff,0x81, - 0x02,0x35,0x0f,0x07,0x3f,0x15,0x0c,0x4a,0x1c,0x2d,0x5f,0x1e, - 0x4f,0x74,0x20,0x59,0x83,0x24,0x64,0x92,0x28,0x82,0xa1,0x2e, - 0xa1,0xb0,0x34,0xa9,0xc1,0x3a,0xb2,0xd2,0x41,0xc4,0xd9,0x45, - 0xd6,0xe1,0x49,0xe4,0xf0,0x4e,0xf2,0xff,0x53,0xf2,0xff,0x53, -}; - -// ---------------------------------------------------------------------------- -// Reset -// ---------------------------------------------------------------------------- -void region_Reset( ) { - if(region_type == REGION_PAL || (region_type == REGION_AUTO && cartridge_region == REGION_PAL)) { - maria_displayArea = REGION_DISPLAY_AREA_PAL; - maria_visibleArea = REGION_VISIBLE_AREA_PAL; - if(palette_default) - palette_Load(REGION_PALETTE_PAL); // Added check for default - bberlin - prosystem_frequency = REGION_FREQUENCY_PAL; - prosystem_scanlines = REGION_SCANLINES_PAL; - tia_size = 624; - pokey_size = 624; - } - else { - maria_displayArea = REGION_DISPLAY_AREA_NTSC; - maria_visibleArea = REGION_VISIBLE_AREA_NTSC; - if(palette_default) - palette_Load(REGION_PALETTE_NTSC); // Added check for default - bberlin - prosystem_frequency = REGION_FREQUENCY_NTSC; - prosystem_scanlines = REGION_SCANLINES_NTSC; - tia_size = 524; - pokey_size = 524; - } - pokey_setSampleRate((prosystem_scanlines * prosystem_frequency) << 1); -} diff --git a/core/Riot.cpp b/core/Riot.cpp deleted file mode 100755 index 5c7659b..0000000 --- a/core/Riot.cpp +++ /dev/null @@ -1,270 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Riot.cpp -// ---------------------------------------------------------------------------- -#include "Riot.h" - -bool riot_timing = false; -word riot_timer = TIM64T; -byte riot_intervals; - -byte riot_dra = 0; -byte riot_drb = 0; -static bool riot_elapsed; -static int riot_currentTime; -word riot_clocks; - -void riot_Reset(void) { - riot_SetDRA(0); - riot_SetDRB(0); - - riot_timing = false; - riot_timer = TIM64T; - riot_intervals = 0; - riot_clocks = 0; - - riot_elapsed = false; - riot_currentTime = 0; -} - -// ---------------------------------------------------------------------------- -// SetInput -// +----------+--------------+------------------------------------------------- -// | Offset | Controller | Control -// +----------+--------------+------------------------------------------------- -// | 00 | Joystick 1 | Right -// | 01 | Joystick 1 | Left -// | 02 | Joystick 1 | Down -// | 03 | Joystick 1 | Up -// | 04 | Joystick 1 | Button 1 -// | 05 | Joystick 1 | Button 2 -// | 06 | Joystick 2 | Right -// | 07 | Joystick 2 | Left -// | 08 | Joystick 2 | Down -// | 09 | Joystick 2 | Up -// | 10 | Joystick 2 | Button 1 -// | 11 | Joystick 2 | Button 2 -// | 12 | Console | Reset -// | 13 | Console | Select -// | 14 | Console | Pause -// | 15 | Console | Left Difficulty -// | 16 | Console | Right Difficulty -// +----------+--------------+------------------------------------------------- -void riot_SetInput(const byte* input) { - - /*gdement: Comments are messy, but wanted to document how this all works. - Changed this routine to support 1 vs 2 button modes. - Also added the interaction of CTLSWA and DRA on the SWCHA output, and same for SWCHB. - SWCHA is directionals. SWCHB is console switches and button mode. - button signals are in high bits of INPT0-5.*/ - - memory_ram[SWCHA] = ((~memory_ram[CTLSWA]) | riot_dra); /*SWCHA as driven by RIOT*/ - /*now console switches will force bits to ground:*/ - if (input[0x00]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x80; - if (input[0x01]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x40; - if (input[0x02]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x20; - if (input[0x03]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x10; - if (input[0x06]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x08; - if (input[0x07]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x04; - if (input[0x08]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x02; - if (input[0x09]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x01; - /*Switches can always push the appropriate bit of SWCHA to ground, as in above code block. - In addition, RIOT can be configured to drive ground even when switch is open. - By doing this it's possible for real hardware to behave as if switches are permanently held (tested this).*/ - - - /*As with swcha, the value seen at SWCHB is derived from CTLSWB and DRB (an internal RIOT register) - (Any write to SWCHB actually gets stored in DRB) - If a given bit in CTLSWB is 0 (input mode), then RIOT puts a 1 on SWCHB. - If bit in CTLSWB is 1 (output mode), then RIOT puts stored DRB value on SWCHB. - The SWCHB outputs from RIOT can be overdriven to 0 by console switches. - The CTLSWB/DRB interaction is important at bits 2 and 4, which control button mode for each player. - Bit 5 appears unused, and other bits are the console switches. - - CTLSWB DRB SWCHB result on button mode (for bits 2 and 4) - ------- --- ----- ----------------------------------------- - 0 0 1 1 button mode - this is default state after boot - 0 1 1 1 button mode - 1 0 0 2 button mode - 1 1 1 1 button mode - This chart was confirmed on hardware - From the default state after boot, simply changing CTLSWB to 1 will result in 2 button mode. - Some games rely on this, and don't actually store anything to SWCHB.*/ - - memory_ram[SWCHB] = ((~memory_ram[CTLSWB]) | riot_drb); /*SWCHB as driven by RIOT*/ - - if(input != NULL) - { - /*now the console switches can force certain bits to ground:*/ - if (input[0x0c]) memory_ram[SWCHB] = memory_ram[SWCHB] &~ 0x01; - if (input[0x0d]) memory_ram[SWCHB] = memory_ram[SWCHB] &~ 0x02; - if (input[0x0e]) memory_ram[SWCHB] = memory_ram[SWCHB] &~ 0x08; - if (input[0x0f]) memory_ram[SWCHB] = memory_ram[SWCHB] &~ 0x40; - if (input[0x10]) memory_ram[SWCHB] = memory_ram[SWCHB] &~ 0x80; - } - - /*When in 1 button mode, only the legacy 2600 button signal is active. The others stay off. - When in 2 button mode, only the new signals are active. 2600 button stays off. (tested) - see: http://www.atariage.com/forums/index.php?showtopic=127162 - also see 7800 schematic and RIOT datasheet */ - - if(memory_ram[SWCHB] & 0x04) //first player in 1 button mode - { - memory_ram[INPT0] &= 0x7f; //new style buttons are always off in this mode - memory_ram[INPT1] &= 0x7f; - if(input[0x04] || input[0x05]) //in this mode, either button triggers only the legacy button signal - { - memory_ram[INPT4] &= 0x7f; //this button signal activates by turning off the high bit - } - else - { - memory_ram[INPT4] |= 0x80; - } - } - else //first player in 2 button mode - { - memory_ram[INPT4] |= 0x80; //2600 button is always off in this mode - if(input[0x04]) //left button (button 1) - { - memory_ram[INPT1] |= 0x80; //these buttons activate by turning on the high bit. - } - else - { - memory_ram[INPT1] &= 0x7f; - } - if(input[0x05]) //right button (button 2) - { - memory_ram[INPT0] |= 0x80; - } - else - { - memory_ram[INPT0] &= 0x7f; - } - } - - /*now repeat for 2nd player*/ - if(memory_ram[SWCHB] & 0x10) - { - memory_ram[INPT2] &= 0x7f; - memory_ram[INPT3] &= 0x7f; - if(input[0x0a] || input[0x0b]) - { - memory_ram[INPT5] &= 0x7f; - } - else - { - memory_ram[INPT5] |= 0x80; - } - } - else - { - memory_ram[INPT5] |= 0x80; - if(input[0x0a]) - { - memory_ram[INPT3] |= 0x80; - } - else - { - memory_ram[INPT3] &= 0x7f; - } - if(input[0x0b]) - { - memory_ram[INPT2] |= 0x80; - } - else - { - memory_ram[INPT2] &= 0x7f; - } - } -} - -/*********************************************************************************** -* riot_setDRA(byte data) and riot_setDRB(byte data) gdement -* ------------------------------------------------- -* Stores a value written to SWCHA/SWCHB into the RIOT's internal DRA/DRB registers. -* These are distinct from what you see when reading SWCHA/SWCHB. -***********************************************************************************/ -void riot_SetDRA(byte data) { - riot_dra=data; -} -void riot_SetDRB(byte data) { - riot_drb=data; -} - - -// ---------------------------------------------------------------------------- -// SetTimer -// ---------------------------------------------------------------------------- -void riot_SetTimer(word timer, byte intervals) { - riot_timer = timer; - riot_intervals = intervals; - switch(timer) { - case T1024T: - riot_clocks = 1024; - riot_timing = true; - break; - case TIM1T: - riot_clocks = 1; - riot_timing = true; - break; - case TIM8T: - riot_clocks = 8; - riot_timing = true; - break; - case TIM64T: - riot_clocks = 64; - riot_timing = true; - break; - } - if(riot_timing) { - riot_currentTime = riot_clocks * intervals; - riot_elapsed = false; - } -} - -// ---------------------------------------------------------------------------- -// UpdateTimer -// ---------------------------------------------------------------------------- -void riot_UpdateTimer(byte cycles) { - riot_currentTime -= cycles; - if(!riot_elapsed && riot_currentTime > 0) { - memory_Write(INTIM, riot_currentTime / riot_clocks); - } - else { - if(riot_elapsed) { - if(riot_currentTime >= -255) { - memory_Write(INTIM, riot_currentTime); - } - else { - memory_Write(INTIM, 0); - riot_timing = false; - } - } - else { - riot_currentTime = riot_clocks; - memory_Write(INTIM, 0); - memory_ram[INTFLG] |= 0x80; - riot_elapsed = true; - } - } -} diff --git a/core/Sally.cpp b/core/Sally.cpp deleted file mode 100755 index f4e5946..0000000 --- a/core/Sally.cpp +++ /dev/null @@ -1,1773 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Sally.cpp -// ---------------------------------------------------------------------------- -#include "Sally.h" - -byte sally_a = 0; -byte sally_x = 0; -byte sally_y = 0; -byte sally_p = 0; -byte sally_s = 0; -pair sally_pc = {0}; - -static byte sally_opcode; -static pair sally_address; -static uint sally_cycles; - -// Whether the last operation resulted in a half cycle. (needs to be taken -// into consideration by ProSystem when cycle counting). This can occur when -// a TIA or RIOT are accessed (drops to 1.19Mhz when the TIA or RIOT chips -// are accessed) -bool half_cycle = false; - -struct Flag { - byte C; - byte Z; - byte I; - byte D; - byte B; - byte R; - byte V; - byte N; -}; - -static const Flag SALLY_FLAG = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; - -struct Vector { - word H; - word L; -}; - -static const Vector SALLY_RES = {65533, 65532}; -static const Vector SALLY_NMI = {65531, 65530}; -static const Vector SALLY_IRQ = {65535, 65534}; - -static const byte SALLY_CYCLES[256] = { - 7,6,0,0,0,3,5,0,3,2,2,2,0,4,6,0, - 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, - 6,6,0,0,3,3,5,0,4,2,2,2,4,4,6,0, - 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, - 6,6,0,0,0,3,5,0,3,2,2,2,3,4,6,0, - 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, - 6,6,0,0,0,3,5,0,4,2,2,0,5,4,6,0, - 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, - 0,6,0,0,3,3,3,0,2,0,2,0,4,4,4,0, - 2,6,0,0,4,4,4,0,2,5,2,0,0,5,0,0, - 2,6,2,0,3,3,3,0,2,2,2,0,4,4,4,0, - 2,5,0,0,4,4,4,0,2,4,2,0,4,4,4,0, - 2,6,0,0,3,3,5,0,2,2,2,0,4,4,6,0, - 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, - 2,6,0,0,3,3,5,0,2,2,2,0,4,4,6,0, - 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, -}; - -// ---------------------------------------------------------------------------- -// Push -// ---------------------------------------------------------------------------- -static void sally_Push(byte data) { - memory_Write(sally_s + 256, data); - sally_s--; -} - -// ---------------------------------------------------------------------------- -// Pop -// ---------------------------------------------------------------------------- -static byte sally_Pop( ) { - sally_s++; - return memory_Read(sally_s + 256); -} - -// ---------------------------------------------------------------------------- -// Flags -// ---------------------------------------------------------------------------- -static void sally_Flags(byte data) { - if(!data) { - sally_p |= SALLY_FLAG.Z; - } - else { - sally_p &= ~SALLY_FLAG.Z; - } - if(data & 128) { - sally_p |= SALLY_FLAG.N; - } - else { - sally_p &= ~SALLY_FLAG.N; - } -} - -// ---------------------------------------------------------------------------- -// Branch -// ---------------------------------------------------------------------------- -static void sally_Branch(byte branch) { - if(branch) { - pair temp = sally_pc; - sally_pc.w += (signed char)sally_address.b.l; - - if(temp.b.h != sally_pc.b.h) { - sally_cycles += 2; - } - else { - sally_cycles++; - } - } -} - -// ---------------------------------------------------------------------------- -// Delay -// ---------------------------------------------------------------------------- -static void sally_Delay(byte delta) { - pair address1 = sally_address; - pair address2 = sally_address; - address1.w -= delta; - if(address1.b.h != address2.b.h) { - sally_cycles++; - } -} - -// ---------------------------------------------------------------------------- -// Absolute -// ---------------------------------------------------------------------------- -static void sally_Absolute( ) { - sally_address.b.l = memory_Read(sally_pc.w++); - sally_address.b.h = memory_Read(sally_pc.w++); -} - -// ---------------------------------------------------------------------------- -// AbsoluteX -// ---------------------------------------------------------------------------- -static void sally_AbsoluteX( ) { - sally_address.b.l = memory_Read(sally_pc.w++); - sally_address.b.h = memory_Read(sally_pc.w++); - sally_address.w += sally_x; -} - -// ---------------------------------------------------------------------------- -// AbsoluteY -// ---------------------------------------------------------------------------- -static void sally_AbsoluteY( ) { - sally_address.b.l = memory_Read(sally_pc.w++); - sally_address.b.h = memory_Read(sally_pc.w++); - sally_address.w += sally_y; -} - -// ---------------------------------------------------------------------------- -// Immediate -// ---------------------------------------------------------------------------- -static void sally_Immediate( ) { - sally_address.w = sally_pc.w++; -} - -// ---------------------------------------------------------------------------- -// Indirect -// ---------------------------------------------------------------------------- -static void sally_Indirect( ) { - pair base; - base.b.l = memory_Read(sally_pc.w++); - base.b.h = memory_Read(sally_pc.w++); - sally_address.b.l = memory_Read(base.w); - sally_address.b.h = memory_Read(base.w + 1); -} - -// ---------------------------------------------------------------------------- -// IndirectX -// ---------------------------------------------------------------------------- -static void sally_IndirectX( ) { - sally_address.b.l = memory_Read(sally_pc.w++) + sally_x; - sally_address.b.h = memory_Read(sally_address.b.l + 1); - sally_address.b.l = memory_Read(sally_address.b.l); -} - -// ---------------------------------------------------------------------------- -// IndirectY -// ---------------------------------------------------------------------------- -static void sally_IndirectY( ) { - sally_address.b.l = memory_Read(sally_pc.w++); - sally_address.b.h = memory_Read(sally_address.b.l + 1); - sally_address.b.l = memory_Read(sally_address.b.l); - sally_address.w += sally_y; -} - -// ---------------------------------------------------------------------------- -// Relative -// ---------------------------------------------------------------------------- -static void sally_Relative( ) { - sally_address.w = memory_Read(sally_pc.w++); -} - -// ---------------------------------------------------------------------------- -// Zero Page -// ---------------------------------------------------------------------------- -static void sally_ZeroPage( ) { - sally_address.w = memory_Read(sally_pc.w++); -} - -// ---------------------------------------------------------------------------- -// ZeroPageX -// ---------------------------------------------------------------------------- -static void sally_ZeroPageX( ) { - sally_address.w = memory_Read(sally_pc.w++); - sally_address.b.l += sally_x; -} - -// ---------------------------------------------------------------------------- -// ZeroPageY -// ---------------------------------------------------------------------------- -static void sally_ZeroPageY( ) { - sally_address.w = memory_Read(sally_pc.w++); - sally_address.b.l += sally_y; -} - -// ---------------------------------------------------------------------------- -// ADC -// ---------------------------------------------------------------------------- -static void sally_ADC( ) { - byte data = memory_Read(sally_address.w); - - if(sally_p & SALLY_FLAG.D) { - word al = (sally_a & 15) + (data & 15) + (sally_p & SALLY_FLAG.C); - word ah = (sally_a >> 4) + (data >> 4); - - if(al > 9) { - al += 6; - ah++; - } - - if(!(sally_a + data + (sally_p & SALLY_FLAG.C))) { - sally_p |= SALLY_FLAG.Z; - } - else { - sally_p &= ~SALLY_FLAG.Z; - } - - if((ah & 8) != 0) { - sally_p |= SALLY_FLAG.N; - } - else { - sally_p &= ~SALLY_FLAG.N; - } - - if(~(sally_a ^ data) & ((ah << 4) ^ sally_a) & 128) { - sally_p |= SALLY_FLAG.V; - } - else { - sally_p &= ~SALLY_FLAG.V; - } - - if(ah > 9) { - ah += 6; - } - - if(ah > 15) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - sally_a = (ah << 4) | (al & 15); - } - else { - pair temp; - temp.w = sally_a + data + (sally_p & SALLY_FLAG.C); - - if(temp.b.h) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - if(~(sally_a ^ data) & (sally_a ^ temp.b.l) & 128) { - sally_p |= SALLY_FLAG.V; - } - else { - sally_p &= ~SALLY_FLAG.V; - } - - sally_Flags(temp.b.l); - sally_a = temp.b.l; - } -} - -// ---------------------------------------------------------------------------- -// AND -// ---------------------------------------------------------------------------- -static void sally_AND( ) { - sally_a &= memory_Read(sally_address.w); - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// ASLA -// ---------------------------------------------------------------------------- -static void sally_ASLA( ) { - if(sally_a & 128) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - sally_a <<= 1; - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// ASL -// ---------------------------------------------------------------------------- -static void sally_ASL( ) { - byte data = memory_Read(sally_address.w); - - if(data & 128) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - data <<= 1; - memory_Write(sally_address.w, data); - sally_Flags(data); -} - -// ---------------------------------------------------------------------------- -// BCC -// ---------------------------------------------------------------------------- -static void sally_BCC( ) { - sally_Branch(!(sally_p & SALLY_FLAG.C)); -} - -// ---------------------------------------------------------------------------- -// BCS -// ---------------------------------------------------------------------------- -static void sally_BCS( ) { - sally_Branch(sally_p & SALLY_FLAG.C); -} - -// ---------------------------------------------------------------------------- -// BEQ -// ---------------------------------------------------------------------------- -static void sally_BEQ( ) { - sally_Branch(sally_p & SALLY_FLAG.Z); -} - -// ---------------------------------------------------------------------------- -// BIT -// ---------------------------------------------------------------------------- -static void sally_BIT( ) { - byte data = memory_Read(sally_address.w); - - if(!(data & sally_a)) { - sally_p |= SALLY_FLAG.Z; - } - else { - sally_p &= ~SALLY_FLAG.Z; - } - - sally_p &= ~SALLY_FLAG.V; - sally_p &= ~SALLY_FLAG.N; - sally_p |= data & 64; - sally_p |= data & 128; -} - -// ---------------------------------------------------------------------------- -// BMI -// ---------------------------------------------------------------------------- -static void sally_BMI( ) { - sally_Branch(sally_p & SALLY_FLAG.N); -} - -// ---------------------------------------------------------------------------- -// BNE -// ---------------------------------------------------------------------------- -static void sally_BNE( ) { - sally_Branch(!(sally_p & SALLY_FLAG.Z)); -} - -// ---------------------------------------------------------------------------- -// BPL -// ---------------------------------------------------------------------------- -static void sally_BPL( ) { - sally_Branch(!(sally_p & SALLY_FLAG.N)); -} - -// ---------------------------------------------------------------------------- -// BRK -// ---------------------------------------------------------------------------- -static void sally_BRK( ) { - sally_pc.w++; - sally_p |= SALLY_FLAG.B; - - sally_Push(sally_pc.b.h); - sally_Push(sally_pc.b.l); - sally_Push(sally_p); - - sally_p |= SALLY_FLAG.I; - sally_pc.b.l = memory_ram[SALLY_IRQ.L]; - sally_pc.b.h = memory_ram[SALLY_IRQ.H]; -} - -// ---------------------------------------------------------------------------- -// BVC -// ---------------------------------------------------------------------------- -static void sally_BVC( ) { - sally_Branch(!(sally_p & SALLY_FLAG.V)); -} - -// ---------------------------------------------------------------------------- -// BVS -// ---------------------------------------------------------------------------- -static void sally_BVS( ) { - sally_Branch(sally_p & SALLY_FLAG.V); -} - -// ---------------------------------------------------------------------------- -// CLC -// ---------------------------------------------------------------------------- -static void sally_CLC( ) { - sally_p &= ~SALLY_FLAG.C; -} - -// ---------------------------------------------------------------------------- -// CLD -// ---------------------------------------------------------------------------- -static void sally_CLD( ) { - sally_p &= ~SALLY_FLAG.D; -} - -// ---------------------------------------------------------------------------- -// CLI -// ---------------------------------------------------------------------------- -static void sally_CLI( ) { - sally_p &= ~SALLY_FLAG.I; -} - -// ---------------------------------------------------------------------------- -// CLV -// ---------------------------------------------------------------------------- -static void sally_CLV( ) { - sally_p &= ~SALLY_FLAG.V; -} - -// ---------------------------------------------------------------------------- -// CMP -// ---------------------------------------------------------------------------- -static void sally_CMP( ) { - byte data = memory_Read(sally_address.w); - - if(sally_a >= data) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - sally_Flags(sally_a - data); -} - -// ---------------------------------------------------------------------------- -// CPX -// ---------------------------------------------------------------------------- -static void sally_CPX( ) { - byte data = memory_Read(sally_address.w); - - if(sally_x >= data) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - sally_Flags(sally_x - data); -} - -// ---------------------------------------------------------------------------- -// CPY -// ---------------------------------------------------------------------------- -static void sally_CPY( ) { - byte data = memory_Read(sally_address.w); - - if(sally_y >= data) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - sally_Flags(sally_y - data); -} - -// ---------------------------------------------------------------------------- -// DEC -// ---------------------------------------------------------------------------- -static void sally_DEC( ) { - byte data = memory_Read(sally_address.w); - memory_Write(sally_address.w, --data); - sally_Flags(data); -} - -// ---------------------------------------------------------------------------- -// DEX -// ---------------------------------------------------------------------------- -static void sally_DEX( ) { - sally_Flags(--sally_x); -} - -// ---------------------------------------------------------------------------- -// DEY -// ---------------------------------------------------------------------------- -static void sally_DEY( ) { - sally_Flags(--sally_y); -} - -// ---------------------------------------------------------------------------- -// EOR -// ---------------------------------------------------------------------------- -static void sally_EOR( ) { - sally_a ^= memory_Read(sally_address.w); - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// INC -// ---------------------------------------------------------------------------- -static void sally_INC( ) { - byte data = memory_Read(sally_address.w); - memory_Write(sally_address.w, ++data); - sally_Flags(data); -} - -// ---------------------------------------------------------------------------- -// INX -// ---------------------------------------------------------------------------- -static void sally_INX( ) { - sally_Flags(++sally_x); -} - -// ---------------------------------------------------------------------------- -// INY -// ---------------------------------------------------------------------------- -static void sally_INY( ) { - sally_Flags(++sally_y); -} - -// ---------------------------------------------------------------------------- -// JMP -// ---------------------------------------------------------------------------- -static void sally_JMP( ) { - sally_pc = sally_address; -} - -// ---------------------------------------------------------------------------- -// JSR -// ---------------------------------------------------------------------------- -static void sally_JSR( ) { - sally_pc.w--; - sally_Push(sally_pc.b.h); - sally_Push(sally_pc.b.l); - - sally_pc = sally_address; -} - -// ---------------------------------------------------------------------------- -// LDA -// ---------------------------------------------------------------------------- -static void sally_LDA( ) { - sally_a = memory_Read(sally_address.w); - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// LDX -// ---------------------------------------------------------------------------- -static void sally_LDX( ) { - sally_x = memory_Read(sally_address.w); - sally_Flags(sally_x); -} - -// ---------------------------------------------------------------------------- -// LDY -// ---------------------------------------------------------------------------- -static void sally_LDY( ) { - sally_y = memory_Read(sally_address.w); - sally_Flags(sally_y); -} - -// ---------------------------------------------------------------------------- -// LSRA -// ---------------------------------------------------------------------------- -static void sally_LSRA( ) { - sally_p &= ~SALLY_FLAG.C; - sally_p |= sally_a & 1; - - sally_a >>= 1; - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// LSR -// ---------------------------------------------------------------------------- -static void sally_LSR( ) { - byte data = memory_Read(sally_address.w); - - sally_p &= ~SALLY_FLAG.C; - sally_p |= data & 1; - - data >>= 1; - memory_Write(sally_address.w, data); - sally_Flags(data); -} - -// ---------------------------------------------------------------------------- -// NOP -// ---------------------------------------------------------------------------- -static void sally_NOP( ) { -} - -// ---------------------------------------------------------------------------- -// ORA -// ---------------------------------------------------------------------------- -static void sally_ORA( ) { - sally_a |= memory_Read(sally_address.w); - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// PHA -// ---------------------------------------------------------------------------- -static void sally_PHA( ) { - sally_Push(sally_a); -} - -// ---------------------------------------------------------------------------- -// PHP -// ---------------------------------------------------------------------------- -static void sally_PHP( ) { - sally_Push(sally_p); -} - -// ---------------------------------------------------------------------------- -// PLA -// ---------------------------------------------------------------------------- -static void sally_PLA( ) { - sally_a = sally_Pop( ); - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// PLP -// ---------------------------------------------------------------------------- -static void sally_PLP( ) { - sally_p = sally_Pop( ); -} - -// ---------------------------------------------------------------------------- -// ROLA -// ---------------------------------------------------------------------------- -static void sally_ROLA( ) { - byte temp = sally_p; - - if(sally_a & 128) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - sally_a <<= 1; - sally_a |= temp & SALLY_FLAG.C; - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// ROL -// ---------------------------------------------------------------------------- -static void sally_ROL( ) { - byte data = memory_Read(sally_address.w); - byte temp = sally_p; - - if(data & 128) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - data <<= 1; - data |= temp & 1; - memory_Write(sally_address.w, data); - sally_Flags(data); -} - -// ---------------------------------------------------------------------------- -// RORA -// ---------------------------------------------------------------------------- -static void sally_RORA( ) { - byte temp = sally_p; - - sally_p &= ~SALLY_FLAG.C; - sally_p |= sally_a & 1; - - sally_a >>= 1; - if(temp & SALLY_FLAG.C) { - sally_a |= 128; - } - - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// ROR -// ---------------------------------------------------------------------------- -static void sally_ROR( ) { - byte data = memory_Read(sally_address.w); - byte temp = sally_p; - - sally_p &= ~SALLY_FLAG.C; - sally_p |= data & 1; - - data >>= 1; - if(temp & 1) { - data |= 128; - } - - memory_Write(sally_address.w, data); - sally_Flags(data); -} - -// ---------------------------------------------------------------------------- -// RTI -// ---------------------------------------------------------------------------- -static void sally_RTI( ) { - sally_p = sally_Pop( ); - sally_pc.b.l = sally_Pop( ); - sally_pc.b.h = sally_Pop( ); -} - -// ---------------------------------------------------------------------------- -// RTS -// ---------------------------------------------------------------------------- -static void sally_RTS( ) { - sally_pc.b.l = sally_Pop( ); - sally_pc.b.h = sally_Pop( ); - sally_pc.w++; -} - -// ---------------------------------------------------------------------------- -// SBC -// ---------------------------------------------------------------------------- -static void sally_SBC( ) { - byte data = memory_Read(sally_address.w); - - if(sally_p & SALLY_FLAG.D) { - word al = (sally_a & 15) - (data & 15) - !(sally_p & SALLY_FLAG.C); - word ah = (sally_a >> 4) - (data >> 4); - - if(al > 9) { - al -= 6; - ah--; - } - - if(ah > 9) { - ah -= 6; - } - - pair temp; - temp.w = sally_a - data - !(sally_p & SALLY_FLAG.C); - - if(!temp.b.h) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - if((sally_a ^ data) & (sally_a ^ temp.b.l) & 128) { - sally_p |= SALLY_FLAG.V; - } - else { - sally_p &= ~SALLY_FLAG.V; - } - - sally_Flags(temp.b.l); - sally_a = (ah << 4) | (al & 15); - } - else { - pair temp; - temp.w = sally_a - data - !(sally_p & SALLY_FLAG.C); - - if(!temp.b.h) { - sally_p |= SALLY_FLAG.C; - } - else { - sally_p &= ~SALLY_FLAG.C; - } - - if((sally_a ^ data) & (sally_a ^ temp.b.l) & 128) { - sally_p |= SALLY_FLAG.V; - } - else { - sally_p &= ~SALLY_FLAG.V; - } - - sally_Flags(temp.b.l); - sally_a = temp.b.l; - } -} - -// ---------------------------------------------------------------------------- -// SEC -// ---------------------------------------------------------------------------- -static void sally_SEC( ) { - sally_p |= SALLY_FLAG.C; -} - -// ---------------------------------------------------------------------------- -// SED -// ---------------------------------------------------------------------------- -static void sally_SED( ) { - sally_p |= SALLY_FLAG.D; -} - -// ---------------------------------------------------------------------------- -// SEI -// ---------------------------------------------------------------------------- -static void sally_SEI( ) { - sally_p |= SALLY_FLAG.I; -} - -// ---------------------------------------------------------------------------- -// STA -// ---------------------------------------------------------------------------- -static void sally_STA( ) { - memory_Write(sally_address.w, sally_a); -} - -// ---------------------------------------------------------------------------- -// STX -// ---------------------------------------------------------------------------- -static void sally_stx( ) { - memory_Write(sally_address.w, sally_x); -} - -// ---------------------------------------------------------------------------- -// STY -// ---------------------------------------------------------------------------- -static void sally_STY( ) { - memory_Write(sally_address.w, sally_y); -} - -// ---------------------------------------------------------------------------- -// TAX -// ---------------------------------------------------------------------------- -static void sally_TAX( ) { - sally_x = sally_a; - sally_Flags(sally_x); -} - -// ---------------------------------------------------------------------------- -// TAY -// ---------------------------------------------------------------------------- -static void sally_TAY( ) { - sally_y = sally_a; - sally_Flags(sally_y); -} - -// ---------------------------------------------------------------------------- -// TSX -// ---------------------------------------------------------------------------- -static void sally_TSX( ) { - sally_x = sally_s; - sally_Flags(sally_x); -} - -// ---------------------------------------------------------------------------- -// TXA -// ---------------------------------------------------------------------------- -static void sally_TXA( ) { - sally_a = sally_x; - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// TXS -// ---------------------------------------------------------------------------- -static void sally_TXS( ) { - sally_s = sally_x; -} - -// ---------------------------------------------------------------------------- -// TYA -// ---------------------------------------------------------------------------- -static void sally_TYA( ) { - sally_a = sally_y; - sally_Flags(sally_a); -} - -// ---------------------------------------------------------------------------- -// Reset -// ---------------------------------------------------------------------------- -void sally_Reset( ) { - sally_a = 0; - sally_x = 0; - sally_y = 0; - sally_p = SALLY_FLAG.R; - sally_s = 0; - sally_pc.w = 0; -} - -// ---------------------------------------------------------------------------- -// ExecuteInstruction -// ---------------------------------------------------------------------------- -uint sally_ExecuteInstruction( ) { - // Reset half cycle flag - half_cycle = false; - - sally_opcode = memory_Read(sally_pc.w++); - sally_cycles = SALLY_CYCLES[sally_opcode]; - - switch(sally_opcode) { - case 0x00: - sally_BRK( ); - break; - - case 0x01: - sally_IndirectX( ); - sally_ORA( ); - break; - - case 0x05: - sally_ZeroPage( ); - sally_ORA( ); - break; - - case 0x06: - sally_ZeroPage( ); - sally_ASL( ); - break; - - case 0x08: - sally_PHP( ); - break; - - case 0x09: - sally_Immediate( ); - sally_ORA( ); - break; - - case 0x0a: - sally_ASLA( ); - break; - - case 0x0d: - sally_Absolute( ); - sally_ORA( ); - break; - - case 0x0e: - sally_Absolute( ); - sally_ASL( ); - break; - - case 0x10: - sally_Relative( ); - sally_BPL( ); - break; - - case 0x11: - sally_IndirectY( ); - sally_ORA( ); - sally_Delay(sally_y); - break; - - case 0x15: - sally_ZeroPageX( ); - sally_ORA( ); - break; - - case 0x16: - sally_ZeroPageX( ); - sally_ASL( ); - break; - - case 0x18: - sally_CLC( ); - break; - - case 0x19: - sally_AbsoluteY( ); - sally_ORA( ); - sally_Delay(sally_y); - break; - - case 0x1d: - sally_AbsoluteX( ); - sally_ORA( ); - sally_Delay(sally_x); - break; - - case 0x1e: - sally_AbsoluteX( ); - sally_ASL( ); - break; - - case 0x20: - sally_Absolute( ); - sally_JSR( ); - break; - - case 0x21: - sally_IndirectX( ); - sally_AND( ); - break; - - case 0x24: - sally_ZeroPage( ); - sally_BIT( ); - // Add a half cycle if RIOT/TIA location is accessed. We only track - // INPT4 since it is the only one that is accessed during the lightgun - // hit detection loop. This should be extended to take into consideration - // all RIOT and TIA accesses. - if( sally_address.w == INPT4 ) - { - half_cycle = true; - } - break; - - case 0x25: - sally_ZeroPage( ); - sally_AND( ); - break; - - case 0x26: - sally_ZeroPage( ); - sally_ROL( ); - break; - - case 0x28: - sally_PLP( ); - break; - - case 0x29: - sally_Immediate( ); - sally_AND( ); - break; - - case 0x2a: - sally_ROLA( ); - break; - - case 0x2c: - sally_Absolute( ); - sally_BIT( ); - break; - - case 0x2d: - sally_Absolute( ); - sally_AND( ); - break; - - case 0x2e: - sally_Absolute( ); - sally_ROL( ); - break; - - case 0x30: - sally_Relative( ); - sally_BMI( ); - break; - - case 0x31: - sally_IndirectY( ); - sally_AND( ); - sally_Delay(sally_y); - break; - - case 0x35: - sally_ZeroPageX( ); - sally_AND( ); - break; - - case 0x36: - sally_ZeroPageX( ); - sally_ROL( ); - break; - - case 0x38: - sally_SEC( ); - break; - - case 0x39: - sally_AbsoluteY( ); - sally_AND( ); - sally_Delay(sally_y); - break; - - case 0x3d: - sally_AbsoluteX( ); - sally_AND( ); - sally_Delay(sally_x); - break; - - case 0x3e: - sally_AbsoluteX( ); - sally_ROL( ); - break; - - case 0x40: - sally_RTI( ); - break; - - case 0x41: - sally_IndirectX( ); - sally_EOR( ); - break; - - case 0x45: - sally_ZeroPage( ); - sally_EOR( ); - break; - - case 0x46: - sally_ZeroPage( ); - sally_LSR( ); - break; - - case 0x48: - sally_PHA( ); - break; - - case 0x49: - sally_Immediate( ); - sally_EOR( ); - break; - - case 0x4a: - sally_LSRA( ); - break; - - case 0x4c: - sally_Absolute( ); - sally_JMP( ); - break; - - case 0x4d: - sally_Absolute( ); - sally_EOR( ); - break; - - case 0x4e: - sally_Absolute( ); - sally_LSR( ); - break; - - case 0x50: - sally_Relative( ); - sally_BVC( ); - break; - - case 0x51: - sally_IndirectY( ); - sally_EOR( ); - sally_Delay(sally_y); - break; - - case 0x55: - sally_ZeroPageX( ); - sally_EOR( ); - break; - - case 0x56: - sally_ZeroPageX( ); - sally_LSR( ); - break; - - case 0x58: - sally_CLI( ); - break; - - case 0x59: - sally_AbsoluteY( ); - sally_EOR( ); - sally_Delay(sally_y); - break; - - case 0x5d: - sally_AbsoluteX( ); - sally_EOR( ); - sally_Delay(sally_x); - break; - - case 0x5e: - sally_AbsoluteX( ); - sally_LSR( ); - break; - - case 0x60: - sally_RTS( ); - break; - - case 0x61: - sally_IndirectX( ); - sally_ADC( ); - break; - - case 0x65: - sally_ZeroPage( ); - sally_ADC( ); - break; - - case 0x66: - sally_ZeroPage( ); - sally_ROR( ); - break; - - case 0x68: - sally_PLA( ); - break; - - case 0x69: - sally_Immediate( ); - sally_ADC( ); - break; - - case 0x6a: - sally_RORA( ); - break; - - case 0x6c: - sally_Indirect( ); - sally_JMP( ); - break; - - case 0x6d: - sally_Absolute( ); - sally_ADC( ); - break; - - case 0x6e: - sally_Absolute( ); - sally_ROR( ); - break; - - case 0x70: - sally_Relative( ); - sally_BVS( ); - break; - - case 0x71: - sally_IndirectY( ); - sally_ADC( ); - sally_Delay(sally_y); - break; - - case 0x75: - sally_ZeroPageX( ); - sally_ADC( ); - break; - - case 0x76: - sally_ZeroPageX( ); - sally_ROR( ); - break; - - case 0x78: - sally_SEI( ); - break; - - case 0x79: - sally_AbsoluteY( ); - sally_ADC( ); - sally_Delay(sally_y); - break; - - case 0x7d: - sally_AbsoluteX( ); - sally_ADC( ); - sally_Delay(sally_x); - break; - - case 0x7e: - sally_AbsoluteX( ); - sally_ROR( ); - break; - - case 0x81: - sally_IndirectX( ); - sally_STA( ); - break; - - case 0x84: - sally_ZeroPage( ); - sally_STY( ); - break; - - case 0x85: - sally_ZeroPage( ); - sally_STA( ); - break; - - case 0x86: - sally_ZeroPage( ); - sally_stx( ); - break; - - case 0x88: - sally_DEY( ); - break; - - case 0x8a: - sally_TXA( ); - break; - - case 0x8c: - sally_Absolute( ); - sally_STY( ); - break; - - case 0x8d: - sally_Absolute( ); - sally_STA( ); - break; - - case 0x8e: - sally_Absolute( ); - sally_stx( ); - break; - - case 0x90: - sally_Relative( ); - sally_BCC( ); - break; - - case 0x91: - sally_IndirectY( ); - sally_STA( ); - break; - - case 0x94: - sally_ZeroPageX( ); - sally_STY( ); - break; - - case 0x95: - sally_ZeroPageX( ); - sally_STA( ); - break; - - case 0x96: - sally_ZeroPageY( ); - sally_stx( ); - break; - - case 0x98: - sally_TYA( ); - break; - - case 0x99: - sally_AbsoluteY( ); - sally_STA( ); - break; - - case 0x9a: - sally_TXS( ); - break; - - case 0x9d: - sally_AbsoluteX( ); - sally_STA( ); - break; - - case 0xa0: - sally_Immediate( ); - sally_LDY( ); - break; - - case 0xa1: - sally_IndirectX( ); - sally_LDA( ); - break; - - case 0xa2: - sally_Immediate( ); - sally_LDX( ); - break; - - case 0xa4: - sally_ZeroPage( ); - sally_LDY( ); - break; - - case 0xa5: - sally_ZeroPage( ); - sally_LDA( ); - break; - - case 0xa6: - sally_ZeroPage( ); - sally_LDX( ); - break; - - case 0xa8: - sally_TAY( ); - break; - - case 0xa9: - sally_Immediate( ); - sally_LDA( ); - break; - - case 0xaa: - sally_TAX( ); - break; - - case 0xac: - sally_Absolute( ); - sally_LDY( ); - break; - - case 0xad: - sally_Absolute( ); - sally_LDA( ); - break; - - case 0xae: - sally_Absolute( ); - sally_LDX( ); - break; - - case 0xb0: - sally_Relative( ); - sally_BCS( ); - break; - - case 0xb1: - sally_IndirectY( ); - sally_LDA( ); - sally_Delay(sally_y); - break; - - case 0xb4: - sally_ZeroPageX( ); - sally_LDY( ); - break; - - case 0xb5: - sally_ZeroPageX( ); - sally_LDA( ); - break; - - case 0xb6: - sally_ZeroPageY( ); - sally_LDX( ); - break; - - case 0xb8: - sally_CLV( ); - break; - - case 0xb9: - sally_AbsoluteY( ); - sally_LDA( ); - sally_Delay(sally_y); - break; - - case 0xba: - sally_TSX( ); - break; - - case 0xbc: - sally_AbsoluteX( ); - sally_LDY( ); - sally_Delay(sally_x); - break; - - case 0xbd: - sally_AbsoluteX( ); - sally_LDA( ); - sally_Delay(sally_x); - break; - - case 0xbe: - sally_AbsoluteY( ); - sally_LDX( ); - sally_Delay(sally_y); - break; - - case 0xc0: - sally_Immediate( ); - sally_CPY( ); - break; - - case 0xc1: - sally_IndirectX( ); - sally_CMP( ); - break; - - case 0xc4: - sally_ZeroPage( ); - sally_CPY( ); - break; - - case 0xc5: - sally_ZeroPage( ); - sally_CMP( ); - break; - - case 0xc6: - sally_ZeroPage( ); - sally_DEC( ); - break; - - case 0xc8: - sally_INY( ); - break; - - case 0xc9: - sally_Immediate( ); - sally_CMP( ); - break; - - case 0xca: - sally_DEX( ); - break; - - case 0xcc: - sally_Absolute( ); - sally_CPY( ); - break; - - case 0xcd: - sally_Absolute( ); - sally_CMP( ); - break; - - case 0xce: - sally_Absolute( ); - sally_DEC( ); - break; - - case 0xd0: - sally_Relative( ); - sally_BNE( ); - break; - - case 0xd1: - sally_IndirectY( ); - sally_CMP( ); - sally_Delay(sally_y); - break; - - case 0xd5: - sally_ZeroPageX( ); - sally_CMP( ); - break; - - case 0xd6: - sally_ZeroPageX( ); - sally_DEC( ); - break; - - case 0xd8: - sally_CLD( ); - break; - - case 0xd9: - sally_AbsoluteY( ); - sally_CMP( ); - sally_Delay(sally_y); - break; - - case 0xdd: - sally_AbsoluteX( ); - sally_CMP( ); - sally_Delay(sally_x); - break; - - case 0xde: - sally_AbsoluteX( ); - sally_DEC( ); - break; - - case 0xe0: - sally_Immediate( ); - sally_CPX( ); - break; - - case 0xe1: - sally_IndirectX( ); - sally_SBC( ); - break; - - case 0xe4: - sally_ZeroPage( ); - sally_CPX( ); - break; - - case 0xe5: - sally_ZeroPage( ); - sally_SBC( ); - break; - - case 0xe6: - sally_ZeroPage( ); - sally_INC( ); - break; - - case 0xe8: - sally_INX( ); - break; - - case 0xe9: - sally_Immediate( ); - sally_SBC( ); - break; - - case 0xea: - sally_NOP( ); - break; - - case 0xec: - sally_Absolute( ); - sally_CPX( ); - break; - - case 0xed: - sally_Absolute( ); - sally_SBC( ); - break; - - case 0xee: - sally_Absolute( ); - sally_INC( ); - break; - - case 0xf0: - sally_Relative( ); - sally_BEQ( ); - break; - - case 0xf1: - sally_IndirectY( ); - sally_SBC( ); - sally_Delay(sally_y); - break; - - case 0xf5: - sally_ZeroPageX( ); - sally_SBC( ); - break; - - case 0xf6: - sally_ZeroPageX( ); - sally_INC( ); - break; - - case 0xf8: - sally_SED( ); - break; - - case 0xf9: - sally_AbsoluteY( ); - sally_SBC( ); - sally_Delay(sally_y); - break; - - case 0xfd: - sally_AbsoluteX( ); - sally_SBC( ); - sally_Delay(sally_x); - break; - - case 0xfe: - sally_AbsoluteX( ); - sally_INC( ); - break; - - case 0x4b: // ALR (ASR) - sally_Immediate(); - sally_AND(); - sally_LSRA(); - break; - - case 0x0b: // ANC - case 0x2b: { // ANC - sally_Immediate(); - sally_AND(); - if (sally_a & 128) { - sally_p |= SALLY_FLAG.C; - } - else { - //sally_p &= ~SALLY_FLAG.C; - sally_p = (sally_p & ~SALLY_FLAG.C) & 0xFF; - } - break; - } - - default: - break; - } - - return sally_cycles; -} - -// ---------------------------------------------------------------------------- -// ExecuteRES -// ---------------------------------------------------------------------------- -uint sally_ExecuteRES( ) { - sally_p = SALLY_FLAG.I | SALLY_FLAG.R | SALLY_FLAG.Z; - sally_pc.b.l = memory_ram[SALLY_RES.L]; - sally_pc.b.h = memory_ram[SALLY_RES.H]; - return 6; -} - -// ---------------------------------------------------------------------------- -// ExecuteNMI -// ---------------------------------------------------------------------------- -uint sally_ExecuteNMI( ) { - sally_Push(sally_pc.b.h); - sally_Push(sally_pc.b.l); - sally_p &= ~SALLY_FLAG.B; - sally_Push(sally_p); - sally_p |= SALLY_FLAG.I; - sally_pc.b.l = memory_ram[SALLY_NMI.L]; - sally_pc.b.h = memory_ram[SALLY_NMI.H]; - return 7; -} - -// ---------------------------------------------------------------------------- -// Execute IRQ -// ---------------------------------------------------------------------------- -uint sally_ExecuteIRQ( ) { - if(!(sally_p & SALLY_FLAG.I)) { - sally_Push(sally_pc.b.h); - sally_Push(sally_pc.b.l); - sally_p &= ~SALLY_FLAG.B; - sally_Push(sally_p); - sally_p |= SALLY_FLAG.I; - sally_pc.b.l = memory_ram[SALLY_IRQ.L]; - sally_pc.b.h = memory_ram[SALLY_IRQ.H]; - } - return 7; -} diff --git a/core/Tia.cpp b/core/Tia.cpp deleted file mode 100755 index 566f95c..0000000 --- a/core/Tia.cpp +++ /dev/null @@ -1,206 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// TiaSound is Copyright(c) 1997 by Ron Fries -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of version 2 of the GNU Library General Public License -// as published by the Free Software Foundation. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library -// General Public License for more details. -// To obtain a copy of the GNU Library General Public License, write to the -// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// -// Any permitted reproduction of these routines, in whole or in part, must -// bear this legend. -// ---------------------------------------------------------------------------- -// Tia.cpp -// ---------------------------------------------------------------------------- -#include "Tia.h" -#include -#define TIA_POLY4_SIZE 15 -#define TIA_POLY5_SIZE 31 -#define TIA_POLY9_SIZE 511 - -byte tia_buffer[TIA_BUFFER_SIZE] = {0}; -uint tia_size = TIA_BUFFER_SIZE; // previously was 524 - -static const byte TIA_POLY4[ ] = {1,1,0,1,1,1,0,0,0,0,1,0,1,0,0}; -static const byte TIA_POLY5[ ] = {0,0,1,0,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0,1,1,1,0,1,0,1,0,0,0,0,1}; -static const byte TIA_POLY9[ ] = {0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,1,1,0,0,1,0,1,0,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,0,1,1,1,0,1,1,0,0,1,0,0,1,1,1,1,0,1,0,0,0,0,1,1,0,1,1,0,0,0,1,0,0,0,1,1,1,1,0,1,0,1,1,0,1,0,1,0,0,0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,1,1,0,0,1,1,0,1,1,0,0,1,1,1,1,1,0,0,1,1,0,0,0,1,1,0,1,0,0,0,1,1,0,0,1,1,1,1,0,0,1,0,0,0,1,1,1,0,0,1,1,0,1,0,1,1,0,1,1,0,1,0,0,1,0,0,1,1,1,1,1,1,0,1,1,1,1,0,1,1,0,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,1,0,1,1,0,0,0,0,1,0,1,1,1,1,0,1,0,0,0,1,1,0,0,0,1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,0,0,1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,0,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,0,1,0,1,1,1,1,0,0,1,0,1,0,1,1,1,0,0,0,0,0,1,1,0,1,1,0,0,0,1,0,1,0,1,0,0,0,0,1,0,1,1,1,0,0,0,0,1,0,0,1,0,1,0,0,0,1,0,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,1,0,0,1,1,0,1,0,0,1,0,0,0,1,0,0,1,0,1,0,0,0,1,1,0,1,0,0,0,0,0,1,1,1,1,0,0,1,0,0,1,0,1,1,1,1,1,1,1,0,1,0,0,1,0,0,0,1,1,0,1,1,1,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,1,1,0,0,1,0,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0}; -static const byte TIA_DIV31[ ] = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0}; -static byte tia_volume[2] = {0}; -static byte tia_counterMax[2] = {0}; -static byte tia_counter[2] = {0}; -static byte tia_audc[2] = {0}; -static byte tia_audf[2] = {0}; -static byte tia_audv[2] = {0}; -static uint tia_poly4Cntr[2] = {0}; -static uint tia_poly5Cntr[2] = {0}; -static uint tia_poly9Cntr[2] = {0}; -static uint tia_soundCntr = 0; - -// ---------------------------------------------------------------------------- -// ProcessChannel -// ---------------------------------------------------------------------------- -static void tia_ProcessChannel(byte channel) { - tia_poly5Cntr[channel]++; - if(tia_poly5Cntr[channel] == TIA_POLY5_SIZE) { - tia_poly5Cntr[channel] = 0; - } - if(((tia_audc[channel] & 2) == 0) || (((tia_audc[channel] & 1) == 0) && TIA_DIV31[tia_poly5Cntr[channel]]) || (((tia_audc[channel] & 1) == 1) && TIA_POLY5[tia_poly5Cntr[channel]])) { - if(tia_audc[channel] & 4) { - tia_volume[channel] = (!tia_volume[channel])? tia_audv[channel]: 0; - } - else if(tia_audc[channel] & 8) { - if(tia_audc[channel] == 8) { - tia_poly9Cntr[channel]++; - if(tia_poly9Cntr[channel] == TIA_POLY9_SIZE) { - tia_poly9Cntr[channel] = 0; - } - tia_volume[channel] = (TIA_POLY9[tia_poly9Cntr[channel]])? tia_audv[channel]: 0; - } - else { - tia_volume[channel] = (TIA_POLY5[tia_poly5Cntr[channel]])? tia_audv[channel]: 0; - } - } - else { - tia_poly4Cntr[channel]++; - if(tia_poly4Cntr[channel] == TIA_POLY4_SIZE) { - tia_poly4Cntr[channel] = 0; - } - tia_volume[channel] = (TIA_POLY4[tia_poly4Cntr[channel]])? tia_audv[channel]: 0; - } - } -} - - -// ---------------------------------------------------------------------------- -// Reset -// ---------------------------------------------------------------------------- -void tia_Reset( ) { - tia_soundCntr = 0; - for(int index = 0; index < 2; index++) { - tia_volume[index] = 0; - tia_counterMax[index] = 0; - tia_counter[index] = 0; - tia_audc[index] = 0; - tia_audf[index] = 0; - tia_audv[index] = 0; - tia_poly4Cntr[index] = 0; - tia_poly5Cntr[index] = 0; - tia_poly9Cntr[index] = 0; - } - tia_Clear( ); -} - -// ---------------------------------------------------------------------------- -// Clear -// ---------------------------------------------------------------------------- -void tia_Clear( ) { - tia_soundCntr = 0; - memset(tia_buffer, 0, TIA_BUFFER_SIZE); -} - -// ---------------------------------------------------------------------------- -// SetRegister -// ---------------------------------------------------------------------------- -void tia_SetRegister(word address, byte data) { - byte channel; - byte frequency; - - switch(address) { - case AUDC0: - tia_audc[0] = data & 15; - channel = 0; - break; - case AUDC1: - tia_audc[1] = data & 15; - channel = 1; - break; - case AUDF0: - tia_audf[0] = data & 31; - channel = 0; - break; - case AUDF1: - tia_audf[1] = data & 31; - channel = 1; - break; - case AUDV0: - tia_audv[0] = (data & 15) << 2; - channel = 0; - break; - case AUDV1: - tia_audv[1] = (data & 15) << 2; - channel = 1; - break; - default: - return; - } - - if(tia_audc[channel] == 0) { - frequency = 0; - tia_volume[channel] = tia_audv[channel]; - } - else { - frequency = tia_audf[channel] + 1; - if(tia_audc[channel] > 11) { - frequency *= 3; - } - } - - if(frequency != tia_counterMax[channel]) { - tia_counterMax[channel] = frequency; - if(tia_counter[channel] == 0 || frequency == 0) { - tia_counter[channel] = frequency; - } - } -} - -// -------------------------------------------------------------------------------------- -// Process -// -------------------------------------------------------------------------------------- -void tia_Process(uint length) { - for(uint index = 0; index < length; index++) { - if(tia_counter[0] > 1) { - tia_counter[0]--; - } - else if(tia_counter[0] == 1) { - tia_counter[0] = tia_counterMax[0]; - tia_ProcessChannel(0); - } - if(tia_counter[1] > 1) { - tia_counter[1]--; - } - else if(tia_counter[1] == 1) { - tia_counter[1] = tia_counterMax[1]; - tia_ProcessChannel(1); - } - tia_buffer[tia_soundCntr++] = tia_volume[0] + tia_volume[1]; - if(tia_soundCntr >= tia_size) { - tia_soundCntr = 0; - } - } -} diff --git a/core/Timer.cpp b/core/Timer.cpp deleted file mode 100755 index 3619d52..0000000 --- a/core/Timer.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator -// -// ---------------------------------------------------------------------------- -// Copyright 2005 Greg Stanton -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. -// ---------------------------------------------------------------------------- -// Timer.cpp -// ---------------------------------------------------------------------------- -#include "Timer.h" - -typedef unsigned long long uInt64; - -static uInt64 timer_currentTime; -static uInt64 timer_nextTime; -static uInt64 timer_counterFrequency; -static uint timer_frameTime; -static bool timer_usingCounter = false; -# if 0 -// ---------------------------------------------------------------------------- -// Initialize -// ---------------------------------------------------------------------------- -void timer_Initialize( ) { - timer_usingCounter = (QueryPerformanceFrequency((LARGE_INTEGER*)&timer_counterFrequency))? true: false; - timeBeginPeriod(1); -} - -// ---------------------------------------------------------------------------- -// Reset -// ---------------------------------------------------------------------------- -void timer_Reset( ) { - if(timer_usingCounter) { - QueryPerformanceCounter((LARGE_INTEGER*)&timer_nextTime); - timer_frameTime = timer_counterFrequency / prosystem_frequency; - timer_nextTime += timer_frameTime; - } - else { - timer_frameTime = (1000.0 / (double)prosystem_frequency) * 1000; - timer_currentTime = timeGetTime( ) * 1000; - timer_nextTime = timer_currentTime + timer_frameTime; - } -} - -// ---------------------------------------------------------------------------- -// IsTime -// ---------------------------------------------------------------------------- -bool timer_IsTime( ) { - if(timer_usingCounter) { - QueryPerformanceCounter((LARGE_INTEGER*)&timer_currentTime); - } - else { - timer_currentTime = timeGetTime( ) * 1000; - } - - if(timer_currentTime >= timer_nextTime) { - timer_nextTime += timer_frameTime; - return true; - } - return false; -} -# endif \ No newline at end of file diff --git a/core/lib/Crypt.h b/core/lib/Crypt.h deleted file mode 100755 index f14a628..0000000 --- a/core/lib/Crypt.h +++ /dev/null @@ -1,132 +0,0 @@ -/* crypt.h -- base code for crypt/uncrypt ZIPfile - - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - This code is a modified version of crypting code in Infozip distribution - - The encryption/decryption parts of this source code (as opposed to the - non-echoing password parts) were originally written in Europe. The - whole source package can be freely distributed, including from the USA. - (Prior to January 2000, re-export from the US was a violation of US law.) - - This encryption code is a direct transcription of the algorithm from - Roger Schlafly, described by Phil Katz in the file appnote.txt. This - file (appnote.txt) is distributed with the PKZIP program (even in the - version without encryption capabilities). - - If you don't need crypting in your application, just define symbols - NOCRYPT and NOUNCRYPT. - - This code support the "Traditional PKWARE Encryption". - - The new AES encryption added on Zip format by Winzip (see the page - http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong - Encryption is not supported. -*/ - -#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) - -/*********************************************************************** - * Return the next byte in the pseudo-random sequence - */ -static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) -{ - unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an - * unpredictable manner on 16-bit systems; not a problem - * with any known compiler so far, though */ - - temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; - return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); -} - -/*********************************************************************** - * Update the encryption keys with the next byte of plain text - */ -static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) -{ - (*(pkeys+0)) = CRC32((*(pkeys+0)), c); - (*(pkeys+1)) += (*(pkeys+0)) & 0xff; - (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; - { - register int keyshift = (int)((*(pkeys+1)) >> 24); - (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); - } - return c; -} - - -/*********************************************************************** - * Initialize the encryption keys and the random header according to - * the given password. - */ -static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) -{ - *(pkeys+0) = 305419896L; - *(pkeys+1) = 591751049L; - *(pkeys+2) = 878082192L; - while (*passwd != '\0') { - update_keys(pkeys,pcrc_32_tab,(int)*passwd); - passwd++; - } -} - -#define zdecode(pkeys,pcrc_32_tab,c) \ - (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) - -#define zencode(pkeys,pcrc_32_tab,c,t) \ - (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) - -#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED - -#define RAND_HEAD_LEN 12 - /* "last resort" source for second part of crypt seed pattern */ -# ifndef ZCR_SEED2 -# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ -# endif - -static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) - const char *passwd; /* password string */ - unsigned char *buf; /* where to write header */ - int bufSize; - unsigned long* pkeys; - const unsigned long* pcrc_32_tab; - unsigned long crcForCrypting; -{ - int n; /* index in random header */ - int t; /* temporary */ - int c; /* random byte */ - unsigned char header[RAND_HEAD_LEN-2]; /* random header */ - static unsigned calls = 0; /* ensure different random header each time */ - - if (bufSize> 7) & 0xff; - header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); - } - /* Encrypt random header (last two bytes is high word of crc) */ - init_keys(passwd, pkeys, pcrc_32_tab); - for (n = 0; n < RAND_HEAD_LEN-2; n++) - { - buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); - } - buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); - buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); - return n; -} - -#endif diff --git a/core/lib/HtmlHelp.h b/core/lib/HtmlHelp.h deleted file mode 100755 index 49e2ec5..0000000 --- a/core/lib/HtmlHelp.h +++ /dev/null @@ -1,426 +0,0 @@ -/**************************************************************************** -* * -* HtmlHelp.h * -* * -* Copyright (c) 1996-1997, Microsoft Corp. All rights reserved. * -* * -****************************************************************************/ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#ifndef __HTMLHELP_H__ -#define __HTMLHELP_H__ - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -// Defines for Win64 -#ifndef _WIN64 -#define DWORD_PTR DWORD -#endif - -// Commands to pass to HtmlHelp() - -#define HH_DISPLAY_TOPIC 0x0000 -#define HH_HELP_FINDER 0x0000 // WinHelp equivalent -#define HH_DISPLAY_TOC 0x0001 -#define HH_DISPLAY_INDEX 0x0002 -#define HH_DISPLAY_SEARCH 0x0003 -#define HH_SET_WIN_TYPE 0x0004 -#define HH_GET_WIN_TYPE 0x0005 -#define HH_GET_WIN_HANDLE 0x0006 -#define HH_ENUM_INFO_TYPE 0x0007 // Get Info type name, call repeatedly to enumerate, -1 at end -#define HH_SET_INFO_TYPE 0x0008 // Add Info type to filter. -#define HH_SYNC 0x0009 -#define HH_RESERVED1 0x000A -#define HH_RESERVED2 0x000B -#define HH_RESERVED3 0x000C -#define HH_KEYWORD_LOOKUP 0x000D -#define HH_DISPLAY_TEXT_POPUP 0x000E // display string resource id or text in a popup window -#define HH_HELP_CONTEXT 0x000F // display mapped numeric value in dwData -#define HH_TP_HELP_CONTEXTMENU 0x0010 // text popup help, same as WinHelp HELP_CONTEXTMENU -#define HH_TP_HELP_WM_HELP 0x0011 // text popup help, same as WinHelp HELP_WM_HELP -#define HH_CLOSE_ALL 0x0012 // close all windows opened directly or indirectly by the caller -#define HH_ALINK_LOOKUP 0x0013 // ALink version of HH_KEYWORD_LOOKUP -#define HH_GET_LAST_ERROR 0x0014 // not currently implemented // See HHERROR.h -#define HH_ENUM_CATEGORY 0x0015 // Get category name, call repeatedly to enumerate, -1 at end -#define HH_ENUM_CATEGORY_IT 0x0016 // Get category info type members, call repeatedly to enumerate, -1 at end -#define HH_RESET_IT_FILTER 0x0017 // Clear the info type filter of all info types. -#define HH_SET_INCLUSIVE_FILTER 0x0018 // set inclusive filtering method for untyped topics to be included in display -#define HH_SET_EXCLUSIVE_FILTER 0x0019 // set exclusive filtering method for untyped topics to be excluded from display -#define HH_INITIALIZE 0x001C // Initializes the help system. -#define HH_UNINITIALIZE 0x001D // Uninitializes the help system. -#define HH_PRETRANSLATEMESSAGE 0x00fd // Pumps messages. (NULL, NULL, MSG*). -#define HH_SET_GLOBAL_PROPERTY 0x00fc // Set a global property. (NULL, NULL, HH_GPROP) - -#define HHWIN_PROP_TAB_AUTOHIDESHOW (1 << 0) // Automatically hide/show tri-pane window -#define HHWIN_PROP_ONTOP (1 << 1) // Top-most window -#define HHWIN_PROP_NOTITLEBAR (1 << 2) // no title bar -#define HHWIN_PROP_NODEF_STYLES (1 << 3) // no default window styles (only HH_WINTYPE.dwStyles) -#define HHWIN_PROP_NODEF_EXSTYLES (1 << 4) // no default extended window styles (only HH_WINTYPE.dwExStyles) -#define HHWIN_PROP_TRI_PANE (1 << 5) // use a tri-pane window -#define HHWIN_PROP_NOTB_TEXT (1 << 6) // no text on toolbar buttons -#define HHWIN_PROP_POST_QUIT (1 << 7) // post WM_QUIT message when window closes -#define HHWIN_PROP_AUTO_SYNC (1 << 8) // automatically ssync contents and index -#define HHWIN_PROP_TRACKING (1 << 9) // send tracking notification messages -#define HHWIN_PROP_TAB_SEARCH (1 << 10) // include search tab in navigation pane -#define HHWIN_PROP_TAB_HISTORY (1 << 11) // include history tab in navigation pane -#define HHWIN_PROP_TAB_FAVORITES (1 << 12) // include favorites tab in navigation pane -#define HHWIN_PROP_CHANGE_TITLE (1 << 13) // Put current HTML title in title bar -#define HHWIN_PROP_NAV_ONLY_WIN (1 << 14) // Only display the navigation window -#define HHWIN_PROP_NO_TOOLBAR (1 << 15) // Don't display a toolbar -#define HHWIN_PROP_MENU (1 << 16) // Menu -#define HHWIN_PROP_TAB_ADVSEARCH (1 << 17) // Advanced FTS UI. -#define HHWIN_PROP_USER_POS (1 << 18) // After initial creation, user controls window size/position -#define HHWIN_PROP_TAB_CUSTOM1 (1 << 19) // Use custom tab #1 -#define HHWIN_PROP_TAB_CUSTOM2 (1 << 20) // Use custom tab #2 -#define HHWIN_PROP_TAB_CUSTOM3 (1 << 21) // Use custom tab #3 -#define HHWIN_PROP_TAB_CUSTOM4 (1 << 22) // Use custom tab #4 -#define HHWIN_PROP_TAB_CUSTOM5 (1 << 23) // Use custom tab #5 -#define HHWIN_PROP_TAB_CUSTOM6 (1 << 24) // Use custom tab #6 -#define HHWIN_PROP_TAB_CUSTOM7 (1 << 25) // Use custom tab #7 -#define HHWIN_PROP_TAB_CUSTOM8 (1 << 26) // Use custom tab #8 -#define HHWIN_PROP_TAB_CUSTOM9 (1 << 27) // Use custom tab #9 -#define HHWIN_TB_MARGIN (1 << 28) // the window type has a margin - -#define HHWIN_PARAM_PROPERTIES (1 << 1) // valid fsWinProperties -#define HHWIN_PARAM_STYLES (1 << 2) // valid dwStyles -#define HHWIN_PARAM_EXSTYLES (1 << 3) // valid dwExStyles -#define HHWIN_PARAM_RECT (1 << 4) // valid rcWindowPos -#define HHWIN_PARAM_NAV_WIDTH (1 << 5) // valid iNavWidth -#define HHWIN_PARAM_SHOWSTATE (1 << 6) // valid nShowState -#define HHWIN_PARAM_INFOTYPES (1 << 7) // valid apInfoTypes -#define HHWIN_PARAM_TB_FLAGS (1 << 8) // valid fsToolBarFlags -#define HHWIN_PARAM_EXPANSION (1 << 9) // valid fNotExpanded -#define HHWIN_PARAM_TABPOS (1 << 10) // valid tabpos -#define HHWIN_PARAM_TABORDER (1 << 11) // valid taborder -#define HHWIN_PARAM_HISTORY_COUNT (1 << 12) // valid cHistory -#define HHWIN_PARAM_CUR_TAB (1 << 13) // valid curNavType - -#define HHWIN_BUTTON_EXPAND (1 << 1) // Expand/contract button -#define HHWIN_BUTTON_BACK (1 << 2) // Back button -#define HHWIN_BUTTON_FORWARD (1 << 3) // Forward button -#define HHWIN_BUTTON_STOP (1 << 4) // Stop button -#define HHWIN_BUTTON_REFRESH (1 << 5) // Refresh button -#define HHWIN_BUTTON_HOME (1 << 6) // Home button -#define HHWIN_BUTTON_BROWSE_FWD (1 << 7) // not implemented -#define HHWIN_BUTTON_BROWSE_BCK (1 << 8) // not implemented -#define HHWIN_BUTTON_NOTES (1 << 9) // not implemented -#define HHWIN_BUTTON_CONTENTS (1 << 10) // not implemented -#define HHWIN_BUTTON_SYNC (1 << 11) // Sync button -#define HHWIN_BUTTON_OPTIONS (1 << 12) // Options button -#define HHWIN_BUTTON_PRINT (1 << 13) // Print button -#define HHWIN_BUTTON_INDEX (1 << 14) // not implemented -#define HHWIN_BUTTON_SEARCH (1 << 15) // not implemented -#define HHWIN_BUTTON_HISTORY (1 << 16) // not implemented -#define HHWIN_BUTTON_FAVORITES (1 << 17) // not implemented -#define HHWIN_BUTTON_JUMP1 (1 << 18) -#define HHWIN_BUTTON_JUMP2 (1 << 19) -#define HHWIN_BUTTON_ZOOM (1 << 20) -#define HHWIN_BUTTON_TOC_NEXT (1 << 21) -#define HHWIN_BUTTON_TOC_PREV (1 << 22) - -#define HHWIN_DEF_BUTTONS \ - (HHWIN_BUTTON_EXPAND | \ - HHWIN_BUTTON_BACK | \ - HHWIN_BUTTON_OPTIONS | \ - HHWIN_BUTTON_PRINT) - -// Button IDs - -#define IDTB_EXPAND 200 -#define IDTB_CONTRACT 201 -#define IDTB_STOP 202 -#define IDTB_REFRESH 203 -#define IDTB_BACK 204 -#define IDTB_HOME 205 -#define IDTB_SYNC 206 -#define IDTB_PRINT 207 -#define IDTB_OPTIONS 208 -#define IDTB_FORWARD 209 -#define IDTB_NOTES 210 // not implemented -#define IDTB_BROWSE_FWD 211 -#define IDTB_BROWSE_BACK 212 -#define IDTB_CONTENTS 213 // not implemented -#define IDTB_INDEX 214 // not implemented -#define IDTB_SEARCH 215 // not implemented -#define IDTB_HISTORY 216 // not implemented -#define IDTB_FAVORITES 217 // not implemented -#define IDTB_JUMP1 218 -#define IDTB_JUMP2 219 -#define IDTB_CUSTOMIZE 221 -#define IDTB_ZOOM 222 -#define IDTB_TOC_NEXT 223 -#define IDTB_TOC_PREV 224 - -// Notification codes - -#define HHN_FIRST (0U-860U) -#define HHN_LAST (0U-879U) - -#define HHN_NAVCOMPLETE (HHN_FIRST-0) -#define HHN_TRACK (HHN_FIRST-1) -#define HHN_WINDOW_CREATE (HHN_FIRST-2) - -typedef struct tagHHN_NOTIFY -{ - NMHDR hdr; - PCSTR pszUrl; // Multi-byte, null-terminated string -} HHN_NOTIFY; - -typedef struct tagHH_POPUP -{ - int cbStruct; // sizeof this structure - HINSTANCE hinst; // instance handle for string resource - UINT idString; // string resource id, or text id if pszFile is specified in HtmlHelp call - LPCTSTR pszText; // used if idString is zero - POINT pt; // top center of popup window - COLORREF clrForeground; // use -1 for default - COLORREF clrBackground; // use -1 for default - RECT rcMargins; // amount of space between edges of window and text, -1 for each member to ignore - LPCTSTR pszFont; // facename, point size, char set, BOLD ITALIC UNDERLINE -} HH_POPUP; - -typedef struct tagHH_AKLINK -{ - int cbStruct; // sizeof this structure - BOOL fReserved; // must be FALSE (really!) - LPCTSTR pszKeywords; // semi-colon separated keywords - LPCTSTR pszUrl; // URL to jump to if no keywords found (may be NULL) - LPCTSTR pszMsgText; // Message text to display in MessageBox if pszUrl is NULL and no keyword match - LPCTSTR pszMsgTitle; // Message text to display in MessageBox if pszUrl is NULL and no keyword match - LPCTSTR pszWindow; // Window to display URL in - BOOL fIndexOnFail; // Displays index if keyword lookup fails. -} HH_AKLINK; - -enum { - HHWIN_NAVTYPE_TOC, - HHWIN_NAVTYPE_INDEX, - HHWIN_NAVTYPE_SEARCH, - HHWIN_NAVTYPE_FAVORITES, - HHWIN_NAVTYPE_HISTORY, // not implemented - HHWIN_NAVTYPE_AUTHOR, - HHWIN_NAVTYPE_CUSTOM_FIRST = 11 -}; - -enum { - IT_INCLUSIVE, - IT_EXCLUSIVE, - IT_HIDDEN, -}; - -typedef struct tagHH_ENUM_IT -{ - int cbStruct; // size of this structure - int iType; // the type of the information type ie. Inclusive, Exclusive, or Hidden - LPCSTR pszCatName; // Set to the name of the Category to enumerate the info types in a category; else NULL - LPCSTR pszITName; // volitile pointer to the name of the infotype. Allocated by call. Caller responsible for freeing - LPCSTR pszITDescription; // volitile pointer to the description of the infotype. -} HH_ENUM_IT, *PHH_ENUM_IT; - -typedef struct tagHH_ENUM_CAT -{ - int cbStruct; // size of this structure - LPCSTR pszCatName; // volitile pointer to the category name - LPCSTR pszCatDescription; // volitile pointer to the category description -} HH_ENUM_CAT, *PHH_ENUM_CAT; - -typedef struct tagHH_SET_INFOTYPE -{ - int cbStruct; // the size of this structure - LPCSTR pszCatName; // the name of the category, if any, the InfoType is a member of. - LPCSTR pszInfoTypeName; // the name of the info type to add to the filter -} HH_SET_INFOTYPE, *PHH_SET_INFOTYPE; - -typedef DWORD HH_INFOTYPE; -typedef HH_INFOTYPE* PHH_INFOTYPE; - -enum { - HHWIN_NAVTAB_TOP, - HHWIN_NAVTAB_LEFT, - HHWIN_NAVTAB_BOTTOM, -}; - -#define HH_MAX_TABS 19 // maximum number of tabs - -enum { - HH_TAB_CONTENTS, - HH_TAB_INDEX, - HH_TAB_SEARCH, - HH_TAB_FAVORITES, - HH_TAB_HISTORY, - HH_TAB_AUTHOR, - - HH_TAB_CUSTOM_FIRST = 11, - HH_TAB_CUSTOM_LAST = HH_MAX_TABS -}; - -#define HH_MAX_TABS_CUSTOM (HH_TAB_CUSTOM_LAST - HH_TAB_CUSTOM_FIRST + 1) - -// HH_DISPLAY_SEARCH Command Related Structures and Constants - -#define HH_FTS_DEFAULT_PROXIMITY (-1) - -typedef struct tagHH_FTS_QUERY -{ - int cbStruct; // Sizeof structure in bytes. - BOOL fUniCodeStrings; // TRUE if all strings are unicode. - LPCTSTR pszSearchQuery; // String containing the search query. - LONG iProximity; // Word proximity. - BOOL fStemmedSearch; // TRUE for StemmedSearch only. - BOOL fTitleOnly; // TRUE for Title search only. - BOOL fExecute; // TRUE to initiate the search. - LPCTSTR pszWindow; // Window to display in -} HH_FTS_QUERY; - -// HH_WINTYPE Structure - -typedef struct tagHH_WINTYPE { - int cbStruct; // IN: size of this structure including all Information Types - BOOL fUniCodeStrings; // IN/OUT: TRUE if all strings are in UNICODE - LPCTSTR pszType; // IN/OUT: Name of a type of window - DWORD fsValidMembers; // IN: Bit flag of valid members (HHWIN_PARAM_) - DWORD fsWinProperties; // IN/OUT: Properties/attributes of the window (HHWIN_) - - LPCTSTR pszCaption; // IN/OUT: Window title - DWORD dwStyles; // IN/OUT: Window styles - DWORD dwExStyles; // IN/OUT: Extended Window styles - RECT rcWindowPos; // IN: Starting position, OUT: current position - int nShowState; // IN: show state (e.g., SW_SHOW) - - HWND hwndHelp; // OUT: window handle - HWND hwndCaller; // OUT: who called this window - - HH_INFOTYPE* paInfoTypes; // IN: Pointer to an array of Information Types - - // The following members are only valid if HHWIN_PROP_TRI_PANE is set - - HWND hwndToolBar; // OUT: toolbar window in tri-pane window - HWND hwndNavigation; // OUT: navigation window in tri-pane window - HWND hwndHTML; // OUT: window displaying HTML in tri-pane window - int iNavWidth; // IN/OUT: width of navigation window - RECT rcHTML; // OUT: HTML window coordinates - - LPCTSTR pszToc; // IN: Location of the table of contents file - LPCTSTR pszIndex; // IN: Location of the index file - LPCTSTR pszFile; // IN: Default location of the html file - LPCTSTR pszHome; // IN/OUT: html file to display when Home button is clicked - DWORD fsToolBarFlags; // IN: flags controling the appearance of the toolbar - BOOL fNotExpanded; // IN: TRUE/FALSE to contract or expand, OUT: current state - int curNavType; // IN/OUT: UI to display in the navigational pane - int tabpos; // IN/OUT: HHWIN_NAVTAB_TOP, HHWIN_NAVTAB_LEFT, or HHWIN_NAVTAB_BOTTOM - int idNotify; // IN: ID to use for WM_NOTIFY messages - BYTE tabOrder[HH_MAX_TABS + 1]; // IN/OUT: tab order: Contents, Index, Search, History, Favorites, Reserved 1-5, Custom tabs - int cHistory; // IN/OUT: number of history items to keep (default is 30) - LPCTSTR pszJump1; // Text for HHWIN_BUTTON_JUMP1 - LPCTSTR pszJump2; // Text for HHWIN_BUTTON_JUMP2 - LPCTSTR pszUrlJump1; // URL for HHWIN_BUTTON_JUMP1 - LPCTSTR pszUrlJump2; // URL for HHWIN_BUTTON_JUMP2 - RECT rcMinSize; // Minimum size for window (ignored in version 1) - int cbInfoTypes; // size of paInfoTypes; - LPCTSTR pszCustomTabs; // multiple zero-terminated strings -} HH_WINTYPE, *PHH_WINTYPE; - -enum { - HHACT_TAB_CONTENTS, - HHACT_TAB_INDEX, - HHACT_TAB_SEARCH, - HHACT_TAB_HISTORY, - HHACT_TAB_FAVORITES, - - HHACT_EXPAND, - HHACT_CONTRACT, - HHACT_BACK, - HHACT_FORWARD, - HHACT_STOP, - HHACT_REFRESH, - HHACT_HOME, - HHACT_SYNC, - HHACT_OPTIONS, - HHACT_PRINT, - HHACT_HIGHLIGHT, - HHACT_CUSTOMIZE, - HHACT_JUMP1, - HHACT_JUMP2, - HHACT_ZOOM, - HHACT_TOC_NEXT, - HHACT_TOC_PREV, - HHACT_NOTES, - - HHACT_LAST_ENUM, -}; - -typedef struct tagHHNTRACK -{ - NMHDR hdr; - PCSTR pszCurUrl; // Multi-byte, null-terminated string - int idAction; // HHACT_ value - HH_WINTYPE* phhWinType; // Current window type structure -} HHNTRACK; - -HWND -WINAPI -HtmlHelpA( - HWND hwndCaller, - LPCSTR pszFile, - UINT uCommand, - DWORD_PTR dwData - ); - -HWND -WINAPI -HtmlHelpW( - HWND hwndCaller, - LPCWSTR pszFile, - UINT uCommand, - DWORD_PTR dwData - ); -#ifdef UNICODE -#define HtmlHelp HtmlHelpW -#else -#define HtmlHelp HtmlHelpA -#endif // !UNICODE - -// Use the following for GetProcAddress to load from hhctrl.ocx - -#define ATOM_HTMLHELP_API_ANSI (LPTSTR)((DWORD)((WORD)(14))) -#define ATOM_HTMLHELP_API_UNICODE (LPTSTR)((DWORD)((WORD)(15))) - -/////////////////////////////////////////////////////////////////////////////// -// -// Global Control Properties. -// -typedef enum tagHH_GPROPID -{ - HH_GPROPID_SINGLETHREAD=1, // VARIANT_BOOL: True for single thread - HH_GPROPID_TOOLBAR_MARGIN=2, // long: Provides a left/right margin around the toolbar. - HH_GPROPID_UI_LANGUAGE=3, // long: LangId of the UI. - HH_GPROPID_CURRENT_SUBSET=4, // BSTR: Current subset. - HH_GPROPID_CONTENT_LANGUAGE=5 // long: LandId for desired content. -} HH_GPROPID; - -/////////////////////////////////////////////////////////////////////////////// -// -// Global Property structure -// -#ifdef __oaidl_h__ - -#pragma pack(push, 8) - -typedef struct tagHH_GLOBAL_PROPERTY -{ - HH_GPROPID id; - VARIANT var; -} HH_GLOBAL_PROPERTY ; - -#pragma pack(pop) -#endif - -#ifdef __cplusplus -} -#endif // __cplusplus - -#endif // __HTMLHELP_H__ diff --git a/core/lib/Ioapi.h b/core/lib/Ioapi.h deleted file mode 100755 index e73a3b2..0000000 --- a/core/lib/Ioapi.h +++ /dev/null @@ -1,75 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - files using zlib + zip or unzip API - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant -*/ - -#ifndef _ZLIBIOAPI_H -#define _ZLIBIOAPI_H - - -#define ZLIB_FILEFUNC_SEEK_CUR (1) -#define ZLIB_FILEFUNC_SEEK_END (2) -#define ZLIB_FILEFUNC_SEEK_SET (0) - -#define ZLIB_FILEFUNC_MODE_READ (1) -#define ZLIB_FILEFUNC_MODE_WRITE (2) -#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) - -#define ZLIB_FILEFUNC_MODE_EXISTING (4) -#define ZLIB_FILEFUNC_MODE_CREATE (8) - - -#ifndef ZCALLBACK - -#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) -#define ZCALLBACK CALLBACK -#else -#define ZCALLBACK -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); -typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); -typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); -typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); - -typedef struct zlib_filefunc_def_s -{ - open_file_func zopen_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell_file_func ztell_file; - seek_file_func zseek_file; - close_file_func zclose_file; - testerror_file_func zerror_file; - voidpf opaque; -} zlib_filefunc_def; - - - -void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); - -#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) -#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) -#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) -#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) -#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) -#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) - - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/core/lib/Unzip.c b/core/lib/Unzip.c deleted file mode 100755 index f2a6ffa..0000000 --- a/core/lib/Unzip.c +++ /dev/null @@ -1,1299 +0,0 @@ -/* unzip.c -- IO on .zip files using zlib - Version 0.15 beta, Mar 19th, 1998, - - Read unzip.h for more info -*/ - -#include -#include -#include -#include "zlib.h" -#include "unzip.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - - - -#if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \ - !defined(CASESENSITIVITYDEFAULT_NO) -#define CASESENSITIVITYDEFAULT_NO -#endif - - -#ifndef UNZ_BUFSIZE -#define UNZ_BUFSIZE (16384) -#endif - -#ifndef UNZ_MAXFILENAMEINZIP -#define UNZ_MAXFILENAMEINZIP (256) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) - - -/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef SEEK_END -#define SEEK_END 2 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -const char unz_copyright[] = - " unzip 0.15 Copyright 1998 Gilles Vollant "; - -/* unz_file_info_interntal contain internal info about a file in zipfile*/ -typedef struct unz_file_info_internal_s -{ - uLong offset_curfile;/* relative offset of local header 4 bytes */ -} unz_file_info_internal; - - -/* file_in_zip_read_info_s contain internal information about a file in zipfile, - when reading and decompress it */ -typedef struct -{ - char *read_buffer; /* internal buffer for compressed data */ - z_stream stream; /* zLib stream structure for inflate */ - - uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ - uLong stream_initialised; /* flag set if stream structure is initialised*/ - - uLong offset_local_extrafield;/* offset of the local extra field */ - uInt size_local_extrafield;/* size of the local extra field */ - uLong pos_local_extrafield; /* position in the local extra field in read*/ - - uLong crc32; /* crc32 of all data uncompressed */ - uLong crc32_wait; /* crc32 we must obtain after decompress all */ - uLong rest_read_compressed; /* number of byte to be decompressed */ - uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ - FILE* file; /* io structore of the zipfile */ - uLong compression_method; /* compression method (0==store) */ - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ -} file_in_zip_read_info_s; - - -/* unz_s contain internal information about the zipfile -*/ -typedef struct -{ - FILE* file; /* io structore of the zipfile */ - unz_global_info gi; /* public global information */ - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - uLong num_file; /* number of the current file in the zipfile*/ - uLong pos_in_central_dir; /* pos of the current file in the central dir*/ - uLong current_file_ok; /* flag about the usability of the current file*/ - uLong central_pos; /* position of the beginning of the central dir*/ - - uLong size_central_dir; /* size of the central directory */ - uLong offset_central_dir; /* offset of start of central directory with - respect to the starting disk number */ - - unz_file_info cur_file_info; /* public info about the current file in zip*/ - unz_file_info_internal cur_file_info_internal; /* private info about it*/ - file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current - file if we are decompressing it */ -} unz_s; - - -/* =========================================================================== - Read a byte from a gz_stream; update next_in and avail_in. Return EOF - for end of file. - IN assertion: the stream s has been sucessfully opened for reading. -*/ - - -local int unzlocal_getByte(fin,pi) - FILE *fin; - int *pi; -{ - unsigned char c; - int err = fread(&c, 1, 1, fin); - if (err==1) - { - *pi = (int)c; - return UNZ_OK; - } - else - { - if (ferror(fin)) - return UNZ_ERRNO; - else - return UNZ_EOF; - } -} - - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int unzlocal_getShort (fin,pX) - FILE* fin; - uLong *pX; -{ - uLong x ; - int i; - int err; - - err = unzlocal_getByte(fin,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<8; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unzlocal_getLong (fin,pX) - FILE* fin; - uLong *pX; -{ - uLong x ; - int i; - int err; - - err = unzlocal_getByte(fin,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<8; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<16; - - if (err==UNZ_OK) - err = unzlocal_getByte(fin,&i); - x += ((uLong)i)<<24; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - - -/* My own strcmpi / strcasecmp */ -local int strcmpcasenosensitive_internal (fileName1,fileName2) - const char* fileName1; - const char* fileName2; -{ - for (;;) - { - char c1=*(fileName1++); - char c2=*(fileName2++); - if ((c1>='a') && (c1<='z')) - c1 -= 0x20; - if ((c2>='a') && (c2<='z')) - c2 -= 0x20; - if (c1=='\0') - return ((c2=='\0') ? 0 : -1); - if (c2=='\0') - return 1; - if (c1c2) - return 1; - } -} - - -#ifdef CASESENSITIVITYDEFAULT_NO -#define CASESENSITIVITYDEFAULTVALUE 2 -#else -#define CASESENSITIVITYDEFAULTVALUE 1 -#endif - -#ifndef STRCMPCASENOSENTIVEFUNCTION -#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal -#endif - -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) - -*/ -extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) - const char* fileName1; - const char* fileName2; - int iCaseSensitivity; -{ - if (iCaseSensitivity==0) - iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; - - if (iCaseSensitivity==1) - return strcmp(fileName1,fileName2); - - return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); -} - -#define BUFREADCOMMENT (0x400) - -/* - Locate the Central directory of a zipfile (at the end, just before - the global comment) -*/ -local uLong unzlocal_SearchCentralDir(fin) - FILE *fin; -{ - unsigned char* buf; - uLong uSizeFile; - uLong uBackRead; - uLong uMaxBack=0xffff; /* maximum size of global comment */ - uLong uPosFound=0; - - if (fseek(fin,0,SEEK_END) != 0) - return 0; - - - uSizeFile = ftell( fin ); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); - if (fseek(fin,uReadPos,SEEK_SET)!=0) - break; - - if (fread(buf,(uInt)uReadSize,1,fin)!=1) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - return uPosFound; -} - -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer - "zlib/zlib109.zip". - If the zipfile cannot be opened (file don't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. -*/ -extern unzFile ZEXPORT unzOpen (path) - const char *path; -{ - unz_s us; - unz_s *s; - uLong central_pos,uL; - FILE * fin ; - - uLong number_disk; /* number of the current dist, used for - spaning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used - for spaning ZIP, unsupported, always 0*/ - uLong number_entry_CD; /* total number of entries in - the central dir - (same than number_entry on nospan) */ - - int err=UNZ_OK; - - if (unz_copyright[0]!=' ') - return NULL; - - fin=fopen(path,"rb"); - if (fin==NULL) - return NULL; - - central_pos = unzlocal_SearchCentralDir(fin); - if (central_pos==0) - err=UNZ_ERRNO; - - if (fseek(fin,central_pos,SEEK_SET)!=0) - err=UNZ_ERRNO; - - /* the signature, already checked */ - if (unzlocal_getLong(fin,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of this disk */ - if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of the disk with the start of the central directory */ - if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central dir on this disk */ - if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central dir */ - if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - if ((number_entry_CD!=us.gi.number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=UNZ_BADZIPFILE; - - /* size of the central directory */ - if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - /* offset of start of central directory with respect to the - starting disk number */ - if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - /* zipfile comment length */ - if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK) - err=UNZ_ERRNO; - - if ((central_pospfile_in_zip_read!=NULL) - unzCloseCurrentFile(file); - - fclose(s->file); - TRYFREE(s); - return UNZ_OK; -} - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) - unzFile file; - unz_global_info *pglobal_info; -{ - unz_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - *pglobal_info=s->gi; - return UNZ_OK; -} - - -/* - Translate date/time from Dos format to tm_unz (readable more easilty) -*/ -local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) - uLong ulDosDate; - tm_unz* ptm; -{ - uLong uDate; - uDate = (uLong)(ulDosDate>>16); - ptm->tm_mday = (uInt)(uDate&0x1f) ; - ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; - ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; - - ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); - ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; - ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; -} - -/* - Get Info about the current file in the zipfile, with internal only info -*/ -local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, - unz_file_info *pfile_info, - unz_file_info_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -local int unzlocal_GetCurrentFileInfoInternal (file, - pfile_info, - pfile_info_internal, - szFileName, fileNameBufferSize, - extraField, extraFieldBufferSize, - szComment, commentBufferSize) - unzFile file; - unz_file_info *pfile_info; - unz_file_info_internal *pfile_info_internal; - char *szFileName; - uLong fileNameBufferSize; - void *extraField; - uLong extraFieldBufferSize; - char *szComment; - uLong commentBufferSize; -{ - unz_s* s; - unz_file_info file_info; - unz_file_info_internal file_info_internal; - int err=UNZ_OK; - uLong uMagic; - long lSeek=0; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0) - err=UNZ_ERRNO; - - - /* we check the magic */ - if (err==UNZ_OK) - { - if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x02014b50) - err=UNZ_BADZIPFILE; - } - - if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK) - err=UNZ_ERRNO; - - unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); - - if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK) - err=UNZ_ERRNO; - - lSeek+=file_info.size_filename; - if ((err==UNZ_OK) && (szFileName!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_filename0) && (fileNameBufferSize>0)) - if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1) - err=UNZ_ERRNO; - lSeek -= uSizeRead; - } - - if ((err==UNZ_OK) && (extraField!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_file_extrafile,lSeek,SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - } - if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) - if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1) - err=UNZ_ERRNO; - lSeek += file_info.size_file_extra - uSizeRead; - } - else - lSeek+=file_info.size_file_extra; - - if ((err==UNZ_OK) && (szComment!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_file_commentfile,lSeek,SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - } - if ((file_info.size_file_comment>0) && (commentBufferSize>0)) - if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1) - err=UNZ_ERRNO; - lSeek+=file_info.size_file_comment - uSizeRead; - } - else - lSeek+=file_info.size_file_comment; - - if ((err==UNZ_OK) && (pfile_info!=NULL)) - *pfile_info=file_info; - - if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) - *pfile_info_internal=file_info_internal; - - return err; -} - - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. -*/ -extern int ZEXPORT unzGetCurrentFileInfo (file, - pfile_info, - szFileName, fileNameBufferSize, - extraField, extraFieldBufferSize, - szComment, commentBufferSize) - unzFile file; - unz_file_info *pfile_info; - char *szFileName; - uLong fileNameBufferSize; - void *extraField; - uLong extraFieldBufferSize; - char *szComment; - uLong commentBufferSize; -{ - return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); -} - -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ -extern int ZEXPORT unzGoToFirstFile (file) - unzFile file; -{ - int err=UNZ_OK; - unz_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - s->pos_in_central_dir=s->offset_central_dir; - s->num_file=0; - err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - - -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ -extern int ZEXPORT unzGoToNextFile (file) - unzFile file; -{ - unz_s* s; - int err; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - if (s->num_file+1==s->gi.number_entry) - return UNZ_END_OF_LIST_OF_FILE; - - s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + - s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; - s->num_file++; - err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - - -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzipStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ -extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) - unzFile file; - const char *szFileName; - int iCaseSensitivity; -{ - unz_s* s; - int err; - - - uLong num_fileSaved; - uLong pos_in_central_dirSaved; - - - if (file==NULL) - return UNZ_PARAMERROR; - - if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) - return UNZ_PARAMERROR; - - s=(unz_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - - num_fileSaved = s->num_file; - pos_in_central_dirSaved = s->pos_in_central_dir; - - err = unzGoToFirstFile(file); - - while (err == UNZ_OK) - { - char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; - unzGetCurrentFileInfo(file,NULL, - szCurrentFileName,sizeof(szCurrentFileName)-1, - NULL,0,NULL,0); - if (unzStringFileNameCompare(szCurrentFileName, - szFileName,iCaseSensitivity)==0) - return UNZ_OK; - err = unzGoToNextFile(file); - } - - s->num_file = num_fileSaved ; - s->pos_in_central_dir = pos_in_central_dirSaved ; - return err; -} - - -/* - Read the local header of the current zipfile - Check the coherency of the local header and info in the end of central - directory about this file - store in *piSizeVar the size of extra info in local header - (filename and size of extra field data) -*/ -local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, - poffset_local_extrafield, - psize_local_extrafield) - unz_s* s; - uInt* piSizeVar; - uLong *poffset_local_extrafield; - uInt *psize_local_extrafield; -{ - uLong uMagic,uData,uFlags; - uLong size_filename; - uLong size_extra_field; - int err=UNZ_OK; - - *piSizeVar = 0; - *poffset_local_extrafield = 0; - *psize_local_extrafield = 0; - - if (fseek(s->file,s->cur_file_info_internal.offset_curfile + - s->byte_before_the_zipfile,SEEK_SET)!=0) - return UNZ_ERRNO; - - - if (err==UNZ_OK) - { - if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x04034b50) - err=UNZ_BADZIPFILE; - } - - if (unzlocal_getShort(s->file,&uData) != UNZ_OK) - err=UNZ_ERRNO; -/* - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) - err=UNZ_BADZIPFILE; -*/ - if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(s->file,&uData) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) - err=UNZ_BADZIPFILE; - - if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && - (s->cur_file_info.compression_method!=Z_DEFLATED)) - err=UNZ_BADZIPFILE; - - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */ - err=UNZ_ERRNO; - - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && - ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && - ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && - ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - - if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) - err=UNZ_BADZIPFILE; - - *piSizeVar += (uInt)size_filename; - - if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK) - err=UNZ_ERRNO; - *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + - SIZEZIPLOCALHEADER + size_filename; - *psize_local_extrafield = (uInt)size_extra_field; - - *piSizeVar += (uInt)size_extra_field; - - return err; -} - -/* - Open for reading data the current file in the zipfile. - If there is no error and the file is opened, the return value is UNZ_OK. -*/ -extern int ZEXPORT unzOpenCurrentFile (file) - unzFile file; -{ - int err=UNZ_OK; - int Store; - uInt iSizeVar; - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - uLong offset_local_extrafield; /* offset of the local extra field */ - uInt size_local_extrafield; /* size of the local extra field */ - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - if (!s->current_file_ok) - return UNZ_PARAMERROR; - - if (s->pfile_in_zip_read != NULL) - unzCloseCurrentFile(file); - - if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, - &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) - return UNZ_BADZIPFILE; - - pfile_in_zip_read_info = (file_in_zip_read_info_s*) - ALLOC(sizeof(file_in_zip_read_info_s)); - if (pfile_in_zip_read_info==NULL) - return UNZ_INTERNALERROR; - - pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); - pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; - pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; - pfile_in_zip_read_info->pos_local_extrafield=0; - - if (pfile_in_zip_read_info->read_buffer==NULL) - { - TRYFREE(pfile_in_zip_read_info); - return UNZ_INTERNALERROR; - } - - pfile_in_zip_read_info->stream_initialised=0; - - if ((s->cur_file_info.compression_method!=0) && - (s->cur_file_info.compression_method!=Z_DEFLATED)) - err=UNZ_BADZIPFILE; - Store = s->cur_file_info.compression_method==0; - - pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; - pfile_in_zip_read_info->crc32=0; - pfile_in_zip_read_info->compression_method = - s->cur_file_info.compression_method; - pfile_in_zip_read_info->file=s->file; - pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; - - pfile_in_zip_read_info->stream.total_out = 0; - - if (!Store) - { - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; - pfile_in_zip_read_info->stream.zfree = (free_func)0; - pfile_in_zip_read_info->stream.opaque = (voidpf)0; - - err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); - if (err == Z_OK) - pfile_in_zip_read_info->stream_initialised=1; - /* windowBits is passed < 0 to tell that there is no zlib header. - * Note that in this case inflate *requires* an extra "dummy" byte - * after the compressed stream in order to complete decompression and - * return Z_STREAM_END. - * In unzip, i don't wait absolutely Z_STREAM_END because I known the - * size of both compressed and uncompressed data - */ - } - pfile_in_zip_read_info->rest_read_compressed = - s->cur_file_info.compressed_size ; - pfile_in_zip_read_info->rest_read_uncompressed = - s->cur_file_info.uncompressed_size ; - - - pfile_in_zip_read_info->pos_in_zipfile = - s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + - iSizeVar; - - pfile_in_zip_read_info->stream.avail_in = (uInt)0; - - - s->pfile_in_zip_read = pfile_in_zip_read_info; - return UNZ_OK; -} - - -/* - Read bytes from the current file. - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ -extern int ZEXPORT unzReadCurrentFile (file, buf, len) - unzFile file; - voidp buf; - unsigned len; -{ - int err=UNZ_OK; - uInt iRead = 0; - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if ((pfile_in_zip_read_info->read_buffer == NULL)) - return UNZ_END_OF_LIST_OF_FILE; - if (len==0) - return 0; - - pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; - - pfile_in_zip_read_info->stream.avail_out = (uInt)len; - - if (len>pfile_in_zip_read_info->rest_read_uncompressed) - pfile_in_zip_read_info->stream.avail_out = - (uInt)pfile_in_zip_read_info->rest_read_uncompressed; - - while (pfile_in_zip_read_info->stream.avail_out>0) - { - if ((pfile_in_zip_read_info->stream.avail_in==0) && - (pfile_in_zip_read_info->rest_read_compressed>0)) - { - uInt uReadThis = UNZ_BUFSIZE; - if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; - if (uReadThis == 0) - return UNZ_EOF; - if (fseek(pfile_in_zip_read_info->file, - pfile_in_zip_read_info->pos_in_zipfile + - pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0) - return UNZ_ERRNO; - if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1, - pfile_in_zip_read_info->file)!=1) - return UNZ_ERRNO; - pfile_in_zip_read_info->pos_in_zipfile += uReadThis; - - pfile_in_zip_read_info->rest_read_compressed-=uReadThis; - - pfile_in_zip_read_info->stream.next_in = - (Bytef*)pfile_in_zip_read_info->read_buffer; - pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; - } - - if (pfile_in_zip_read_info->compression_method==0) - { - uInt uDoCopy,i ; - if (pfile_in_zip_read_info->stream.avail_out < - pfile_in_zip_read_info->stream.avail_in) - uDoCopy = pfile_in_zip_read_info->stream.avail_out ; - else - uDoCopy = pfile_in_zip_read_info->stream.avail_in ; - - for (i=0;istream.next_out+i) = - *(pfile_in_zip_read_info->stream.next_in+i); - - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, - pfile_in_zip_read_info->stream.next_out, - uDoCopy); - pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; - pfile_in_zip_read_info->stream.avail_in -= uDoCopy; - pfile_in_zip_read_info->stream.avail_out -= uDoCopy; - pfile_in_zip_read_info->stream.next_out += uDoCopy; - pfile_in_zip_read_info->stream.next_in += uDoCopy; - pfile_in_zip_read_info->stream.total_out += uDoCopy; - iRead += uDoCopy; - } - else - { - uLong uTotalOutBefore,uTotalOutAfter; - const Bytef *bufBefore; - uLong uOutThis; - int flush=Z_SYNC_FLUSH; - - uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; - bufBefore = pfile_in_zip_read_info->stream.next_out; - - /* - if ((pfile_in_zip_read_info->rest_read_uncompressed == - pfile_in_zip_read_info->stream.avail_out) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - flush = Z_FINISH; - */ - err=inflate(&pfile_in_zip_read_info->stream,flush); - - uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; - uOutThis = uTotalOutAfter-uTotalOutBefore; - - pfile_in_zip_read_info->crc32 = - crc32(pfile_in_zip_read_info->crc32,bufBefore, - (uInt)(uOutThis)); - - pfile_in_zip_read_info->rest_read_uncompressed -= - uOutThis; - - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); - - if (err==Z_STREAM_END) - return (iRead==0) ? UNZ_EOF : iRead; - if (err!=Z_OK) - break; - } - } - - if (err==Z_OK) - return iRead; - return err; -} - - -/* - Give the current position in uncompressed data -*/ -extern z_off_t ZEXPORT unztell (file) - unzFile file; -{ - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - return (z_off_t)pfile_in_zip_read_info->stream.total_out; -} - - -/* - return 1 if the end of file was reached, 0 elsewhere -*/ -extern int ZEXPORT unzeof (file) - unzFile file; -{ - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - if (pfile_in_zip_read_info->rest_read_uncompressed == 0) - return 1; - else - return 0; -} - - - -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field that can be read - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ -extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) - unzFile file; - voidp buf; - unsigned len; -{ - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - uInt read_now; - uLong size_to_read; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - size_to_read = (pfile_in_zip_read_info->size_local_extrafield - - pfile_in_zip_read_info->pos_local_extrafield); - - if (buf==NULL) - return (int)size_to_read; - - if (len>size_to_read) - read_now = (uInt)size_to_read; - else - read_now = (uInt)len ; - - if (read_now==0) - return 0; - - if (fseek(pfile_in_zip_read_info->file, - pfile_in_zip_read_info->offset_local_extrafield + - pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0) - return UNZ_ERRNO; - - if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1) - return UNZ_ERRNO; - - return (int)read_now; -} - -/* - Close the file in zip opened with unzipOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ -extern int ZEXPORT unzCloseCurrentFile (file) - unzFile file; -{ - int err=UNZ_OK; - - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if (pfile_in_zip_read_info->rest_read_uncompressed == 0) - { - if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) - err=UNZ_CRCERROR; - } - - - TRYFREE(pfile_in_zip_read_info->read_buffer); - pfile_in_zip_read_info->read_buffer = NULL; - if (pfile_in_zip_read_info->stream_initialised) - inflateEnd(&pfile_in_zip_read_info->stream); - - pfile_in_zip_read_info->stream_initialised = 0; - TRYFREE(pfile_in_zip_read_info); - - s->pfile_in_zip_read=NULL; - - return err; -} - - -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ -extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) - unzFile file; - char *szComment; - uLong uSizeBuf; -{ - unz_s* s; - uLong uReadThis; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - - uReadThis = uSizeBuf; - if (uReadThis>s->gi.size_comment) - uReadThis = s->gi.size_comment; - - if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0) - return UNZ_ERRNO; - - if (uReadThis>0) - { - *szComment='\0'; - if (fread(szComment,(uInt)uReadThis,1,s->file)!=1) - return UNZ_ERRNO; - } - - if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) - *(szComment+s->gi.size_comment)='\0'; - return (int)uReadThis; -} diff --git a/core/lib/Zconf.h b/core/lib/Zconf.h deleted file mode 100755 index 759d757..0000000 --- a/core/lib/Zconf.h +++ /dev/null @@ -1,323 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2003 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#ifndef ZCONF_H -#define ZCONF_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - */ -#ifdef Z_PREFIX -# define deflateInit_ z_deflateInit_ -# define deflate z_deflate -# define deflateEnd z_deflateEnd -# define inflateInit_ z_inflateInit_ -# define inflate z_inflate -# define inflateEnd z_inflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateSetDictionary z_deflateSetDictionary -# define deflateCopy z_deflateCopy -# define deflateReset z_deflateReset -# define deflatePrime z_deflatePrime -# define deflateParams z_deflateParams -# define deflateBound z_deflateBound -# define inflateInit2_ z_inflateInit2_ -# define inflateSetDictionary z_inflateSetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateCopy z_inflateCopy -# define inflateReset z_inflateReset -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound -# define uncompress z_uncompress -# define adler32 z_adler32 -# define crc32 z_crc32 -# define get_crc_table z_get_crc_table - -# define Byte z_Byte -# define uInt z_uInt -# define uLong z_uLong -# define Bytef z_Bytef -# define charf z_charf -# define intf z_intf -# define uIntf z_uIntf -# define uLongf z_uLongf -# define voidpf z_voidpf -# define voidp z_voidp -#endif - -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif -#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) -# define OS2 -#endif -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) -# define WIN32 -#endif -#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) -# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) -# ifndef SYS16BIT -# define SYS16BIT -# endif -# endif -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#ifdef SYS16BIT -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#ifdef __STDC_VERSION__ -# ifndef STDC -# define STDC -# endif -# if __STDC_VERSION__ >= 199901L -# ifndef STDC99 -# define STDC99 -# endif -# endif -#endif -#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) -# define STDC -#endif -#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) -# define STDC -#endif -#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) -# define STDC -#endif -#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) -# define STDC -#endif - -#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ -# define STDC -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const /* note: need a more gentle solution here */ -# endif -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) -# define NO_DUMMY_DECL -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#ifdef SYS16BIT -# if defined(M_I86SM) || defined(M_I86MM) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -# endif -# if (defined(__SMALL__) || defined(__MEDIUM__)) - /* Turbo C small or medium model */ -# define SMALL_MEDIUM -# ifdef __BORLANDC__ -# define FAR _far -# else -# define FAR far -# endif -# endif -#endif - -#if defined(WINDOWS) || defined(WIN32) - /* If building or using zlib as a DLL, define ZLIB_DLL. - * This is not mandatory, but it offers a little performance increase. - */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -# endif -# endif /* ZLIB_DLL */ - /* If building or using zlib with the WINAPI/WINAPIV calling convention, - * define ZLIB_WINAPI. - * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. - */ -# ifdef ZLIB_WINAPI -# ifdef FAR -# undef FAR -# endif -# include - /* No need for _export, use ZLIB.DEF instead. */ - /* For complete Windows compatibility, use WINAPI, not __stdcall. */ -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR CDECL -# endif -# endif -#endif - -#if defined (__BEOS__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT __declspec(dllexport) -# define ZEXPORTVA __declspec(dllexport) -# else -# define ZEXPORT __declspec(dllimport) -# define ZEXPORTVA __declspec(dllimport) -# endif -# endif -#endif - -#ifndef ZEXTERN -# define ZEXTERN extern -#endif -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */ -# include /* for off_t */ -# include /* for SEEK_* and off_t */ -# ifdef VMS -# include /* for off_t */ -# endif -# define z_off_t off_t -#endif -#ifndef SEEK_SET -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif -#ifndef z_off_t -# define z_off_t long -#endif - -#if defined(__OS400__) -#define NO_vsnprintf -#endif - -#if defined(__MVS__) -# define NO_vsnprintf -# ifdef FAR -# undef FAR -# endif -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) -# pragma map(deflateInit_,"DEIN") -# pragma map(deflateInit2_,"DEIN2") -# pragma map(deflateEnd,"DEEND") -# pragma map(deflateBound,"DEBND") -# pragma map(inflateInit_,"ININ") -# pragma map(inflateInit2_,"ININ2") -# pragma map(inflateEnd,"INEND") -# pragma map(inflateSync,"INSY") -# pragma map(inflateSetDictionary,"INSEDI") -# pragma map(compressBound,"CMBND") -# pragma map(inflate_table,"INTABL") -# pragma map(inflate_fast,"INFA") -# pragma map(inflate_copyright,"INCOPY") -#endif - -#endif /* ZCONF_H */ diff --git a/core/lib/Zip.c b/core/lib/Zip.c deleted file mode 100755 index 97d4f8f..0000000 --- a/core/lib/Zip.c +++ /dev/null @@ -1,1220 +0,0 @@ -/* zip.c -- IO on .zip files using zlib - Version 1.01e, February 12th, 2005 - - 27 Dec 2004 Rolf Kalbermatter - Modification to zipOpen2 to support globalComment retrieval. - - Copyright (C) 1998-2005 Gilles Vollant - - Read zip.h for more info -*/ - - -#include -#include -#include -#include -#include "zlib.h" -#include "zip.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -#ifndef VERSIONMADEBY -# define VERSIONMADEBY (0x0) /* platform depedent */ -#endif - -#ifndef Z_BUFSIZE -#define Z_BUFSIZE (16384) -#endif - -#ifndef Z_MAXFILENAMEINZIP -#define Z_MAXFILENAMEINZIP (256) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -/* -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) -*/ - -/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef SEEK_END -#define SEEK_END 2 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -#ifndef DEF_MEM_LEVEL -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -#endif -const char zip_copyright[] = - " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; - - -#define SIZEDATA_INDATABLOCK (4096-(4*4)) - -#define LOCALHEADERMAGIC (0x04034b50) -#define CENTRALHEADERMAGIC (0x02014b50) -#define ENDHEADERMAGIC (0x06054b50) - -#define FLAG_LOCALHEADER_OFFSET (0x06) -#define CRC_LOCALHEADER_OFFSET (0x0e) - -#define SIZECENTRALHEADER (0x2e) /* 46 */ - -typedef struct linkedlist_datablock_internal_s -{ - struct linkedlist_datablock_internal_s* next_datablock; - uLong avail_in_this_block; - uLong filled_in_this_block; - uLong unused; /* for future use and alignement */ - unsigned char data[SIZEDATA_INDATABLOCK]; -} linkedlist_datablock_internal; - -typedef struct linkedlist_data_s -{ - linkedlist_datablock_internal* first_block; - linkedlist_datablock_internal* last_block; -} linkedlist_data; - - -typedef struct -{ - z_stream stream; /* zLib stream structure for inflate */ - int stream_initialised; /* 1 is stream is initialised */ - uInt pos_in_buffered_data; /* last written byte in buffered_data */ - - uLong pos_local_header; /* offset of the local header of the file - currenty writing */ - char* central_header; /* central header data for the current file */ - uLong size_centralheader; /* size of the central header for cur file */ - uLong flag; /* flag of the file currently writing */ - - int method; /* compression method of file currenty wr.*/ - int raw; /* 1 for directly writing raw data */ - Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ - uLong dosDate; - uLong crc32; - int encrypt; -#ifndef NOCRYPT - unsigned long keys[3]; /* keys defining the pseudo-random sequence */ - const unsigned long* pcrc_32_tab; - int crypt_header_size; -#endif -} curfile_info; - -typedef struct -{ - zlib_filefunc_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ - linkedlist_data central_dir;/* datablock with central dir in construction*/ - int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ - curfile_info ci; /* info on the file curretly writing */ - - uLong begin_pos; /* position of the beginning of the zipfile */ - uLong add_position_when_writting_offset; - uLong number_entry; -#ifndef NO_ADDFILEINEXISTINGZIP - char *globalcomment; -#endif -} zip_internal; - - - -#ifndef NOCRYPT -#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED -#include "crypt.h" -#endif - -local linkedlist_datablock_internal* allocate_new_datablock() -{ - linkedlist_datablock_internal* ldi; - ldi = (linkedlist_datablock_internal*) - ALLOC(sizeof(linkedlist_datablock_internal)); - if (ldi!=NULL) - { - ldi->next_datablock = NULL ; - ldi->filled_in_this_block = 0 ; - ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; - } - return ldi; -} - -local void free_datablock(ldi) - linkedlist_datablock_internal* ldi; -{ - while (ldi!=NULL) - { - linkedlist_datablock_internal* ldinext = ldi->next_datablock; - TRYFREE(ldi); - ldi = ldinext; - } -} - -local void init_linkedlist(ll) - linkedlist_data* ll; -{ - ll->first_block = ll->last_block = NULL; -} - -local void free_linkedlist(ll) - linkedlist_data* ll; -{ - free_datablock(ll->first_block); - ll->first_block = ll->last_block = NULL; -} - - -local int add_data_in_datablock(ll,buf,len) - linkedlist_data* ll; - const void* buf; - uLong len; -{ - linkedlist_datablock_internal* ldi; - const unsigned char* from_copy; - - if (ll==NULL) - return ZIP_INTERNALERROR; - - if (ll->last_block == NULL) - { - ll->first_block = ll->last_block = allocate_new_datablock(); - if (ll->first_block == NULL) - return ZIP_INTERNALERROR; - } - - ldi = ll->last_block; - from_copy = (unsigned char*)buf; - - while (len>0) - { - uInt copy_this; - uInt i; - unsigned char* to_copy; - - if (ldi->avail_in_this_block==0) - { - ldi->next_datablock = allocate_new_datablock(); - if (ldi->next_datablock == NULL) - return ZIP_INTERNALERROR; - ldi = ldi->next_datablock ; - ll->last_block = ldi; - } - - if (ldi->avail_in_this_block < len) - copy_this = (uInt)ldi->avail_in_this_block; - else - copy_this = (uInt)len; - - to_copy = &(ldi->data[ldi->filled_in_this_block]); - - for (i=0;ifilled_in_this_block += copy_this; - ldi->avail_in_this_block -= copy_this; - from_copy += copy_this ; - len -= copy_this; - } - return ZIP_OK; -} - - - -/****************************************************************************/ - -#ifndef NO_ADDFILEINEXISTINGZIP -/* =========================================================================== - Inputs a long in LSB order to the given file - nbByte == 1, 2 or 4 (byte, short or long) -*/ - -local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, uLong x, int nbByte)); -local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - uLong x; - int nbByte; -{ - unsigned char buf[4]; - int n; - for (n = 0; n < nbByte; n++) - { - buf[n] = (unsigned char)(x & 0xff); - x >>= 8; - } - if (x != 0) - { /* data overflow - hack for ZIP64 (X Roche) */ - for (n = 0; n < nbByte; n++) - { - buf[n] = 0xff; - } - } - - if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) - return ZIP_ERRNO; - else - return ZIP_OK; -} - -local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte)); -local void ziplocal_putValue_inmemory (dest, x, nbByte) - void* dest; - uLong x; - int nbByte; -{ - unsigned char* buf=(unsigned char*)dest; - int n; - for (n = 0; n < nbByte; n++) { - buf[n] = (unsigned char)(x & 0xff); - x >>= 8; - } - - if (x != 0) - { /* data overflow - hack for ZIP64 */ - for (n = 0; n < nbByte; n++) - { - buf[n] = 0xff; - } - } -} - -/****************************************************************************/ - - -local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) - const tm_zip* ptm; - uLong dosDate; -{ - uLong year = (uLong)ptm->tm_year; - if (year>1980) - year-=1980; - else if (year>80) - year-=80; - return - (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | - ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); -} - - -/****************************************************************************/ - -local int ziplocal_getByte OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, - int *pi)); - -local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - int *pi; -{ - unsigned char c; - int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); - if (err==1) - { - *pi = (int)c; - return ZIP_OK; - } - else - { - if (ZERROR(*pzlib_filefunc_def,filestream)) - return ZIP_ERRNO; - else - return ZIP_EOF; - } -} - - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int ziplocal_getShort OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - uLong *pX; -{ - uLong x ; - int i; - int err; - - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==ZIP_OK) - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<8; - - if (err==ZIP_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int ziplocal_getLong OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - uLong *pX; -{ - uLong x ; - int i; - int err; - - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==ZIP_OK) - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<8; - - if (err==ZIP_OK) - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<16; - - if (err==ZIP_OK) - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<24; - - if (err==ZIP_OK) - *pX = x; - else - *pX = 0; - return err; -} - -#ifndef BUFREADCOMMENT -#define BUFREADCOMMENT (0x400) -#endif -/* - Locate the Central directory of a zipfile (at the end, just before - the global comment) -*/ -local uLong ziplocal_SearchCentralDir OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream)); - -local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; -{ - unsigned char* buf; - uLong uSizeFile; - uLong uBackRead; - uLong uMaxBack=0xffff; /* maximum size of global comment */ - uLong uPosFound=0; - - if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - - uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); - if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - return uPosFound; -} -#endif /* !NO_ADDFILEINEXISTINGZIP*/ - -/************************************************************/ -extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def) - const char *pathname; - int append; - zipcharpc* globalcomment; - zlib_filefunc_def* pzlib_filefunc_def; -{ - zip_internal ziinit; - zip_internal* zi; - int err=ZIP_OK; - - - if (pzlib_filefunc_def==NULL) - //fill_fopen_filefunc(&ziinit.z_filefunc); - return 0; - else - ziinit.z_filefunc = *pzlib_filefunc_def; - - ziinit.filestream = (*(ziinit.z_filefunc.zopen_file)) - (ziinit.z_filefunc.opaque, - pathname, - (append == APPEND_STATUS_CREATE) ? - (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : - (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING)); - - if (ziinit.filestream == NULL) - return NULL; - ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream); - ziinit.in_opened_file_inzip = 0; - ziinit.ci.stream_initialised = 0; - ziinit.number_entry = 0; - ziinit.add_position_when_writting_offset = 0; - init_linkedlist(&(ziinit.central_dir)); - - - zi = (zip_internal*)ALLOC(sizeof(zip_internal)); - if (zi==NULL) - { - ZCLOSE(ziinit.z_filefunc,ziinit.filestream); - return NULL; - } - - /* now we add file in a zipfile */ -# ifndef NO_ADDFILEINEXISTINGZIP - ziinit.globalcomment = NULL; - if (append == APPEND_STATUS_ADDINZIP) - { - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - - uLong size_central_dir; /* size of the central directory */ - uLong offset_central_dir; /* offset of start of central directory */ - uLong central_pos,uL; - - uLong number_disk; /* number of the current dist, used for - spaning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used - for spaning ZIP, unsupported, always 0*/ - uLong number_entry; - uLong number_entry_CD; /* total number of entries in - the central dir - (same than number_entry on nospan) */ - uLong size_comment; - - central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream); - if (central_pos==0) - err=ZIP_ERRNO; - - if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, - central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=ZIP_ERRNO; - - /* the signature, already checked */ - if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK) - err=ZIP_ERRNO; - - /* number of this disk */ - if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK) - err=ZIP_ERRNO; - - /* number of the disk with the start of the central directory */ - if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK) - err=ZIP_ERRNO; - - /* total number of entries in the central dir on this disk */ - if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK) - err=ZIP_ERRNO; - - /* total number of entries in the central dir */ - if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK) - err=ZIP_ERRNO; - - if ((number_entry_CD!=number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=ZIP_BADZIPFILE; - - /* size of the central directory */ - if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&size_central_dir)!=ZIP_OK) - err=ZIP_ERRNO; - - /* offset of start of central directory with respect to the - starting disk number */ - if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK) - err=ZIP_ERRNO; - - /* zipfile global comment length */ - if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK) - err=ZIP_ERRNO; - - if ((central_pos0) - { - ziinit.globalcomment = ALLOC(size_comment+1); - if (ziinit.globalcomment) - { - size_comment = ZREAD(ziinit.z_filefunc, ziinit.filestream,ziinit.globalcomment,size_comment); - ziinit.globalcomment[size_comment]=0; - } - } - - byte_before_the_zipfile = central_pos - - (offset_central_dir+size_central_dir); - ziinit.add_position_when_writting_offset = byte_before_the_zipfile; - - { - uLong size_central_dir_to_read = size_central_dir; - size_t buf_size = SIZEDATA_INDATABLOCK; - void* buf_read = (void*)ALLOC(buf_size); - if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, - offset_central_dir + byte_before_the_zipfile, - ZLIB_FILEFUNC_SEEK_SET) != 0) - err=ZIP_ERRNO; - - while ((size_central_dir_to_read>0) && (err==ZIP_OK)) - { - uLong read_this = SIZEDATA_INDATABLOCK; - if (read_this > size_central_dir_to_read) - read_this = size_central_dir_to_read; - if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this) - err=ZIP_ERRNO; - - if (err==ZIP_OK) - err = add_data_in_datablock(&ziinit.central_dir,buf_read, - (uLong)read_this); - size_central_dir_to_read-=read_this; - } - TRYFREE(buf_read); - } - ziinit.begin_pos = byte_before_the_zipfile; - ziinit.number_entry = number_entry_CD; - - if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, - offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=ZIP_ERRNO; - } - - if (globalcomment) - { - *globalcomment = ziinit.globalcomment; - } -# endif /* !NO_ADDFILEINEXISTINGZIP*/ - - if (err != ZIP_OK) - { -# ifndef NO_ADDFILEINEXISTINGZIP - TRYFREE(ziinit.globalcomment); -# endif /* !NO_ADDFILEINEXISTINGZIP*/ - TRYFREE(zi); - return NULL; - } - else - { - *zi = ziinit; - return (zipFile)zi; - } -} - -extern zipFile ZEXPORT zipOpen (pathname, append) - const char *pathname; - int append; -{ - return zipOpen2(pathname,append,NULL,NULL); -} - -extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - windowBits, memLevel, strategy, - password, crcForCrypting) - zipFile file; - const char* filename; - const zip_fileinfo* zipfi; - const void* extrafield_local; - uInt size_extrafield_local; - const void* extrafield_global; - uInt size_extrafield_global; - const char* comment; - int method; - int level; - int raw; - int windowBits; - int memLevel; - int strategy; - const char* password; - uLong crcForCrypting; -{ - zip_internal* zi; - uInt size_filename; - uInt size_comment; - uInt i; - int err = ZIP_OK; - -# ifdef NOCRYPT - if (password != NULL) - return ZIP_PARAMERROR; -# endif - - if (file == NULL) - return ZIP_PARAMERROR; - if ((method!=0) && (method!=Z_DEFLATED)) - return ZIP_PARAMERROR; - - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 1) - { - err = zipCloseFileInZip (file); - if (err != ZIP_OK) - return err; - } - - - if (filename==NULL) - filename="-"; - - if (comment==NULL) - size_comment = 0; - else - size_comment = (uInt)strlen(comment); - - size_filename = (uInt)strlen(filename); - - if (zipfi == NULL) - zi->ci.dosDate = 0; - else - { - if (zipfi->dosDate != 0) - zi->ci.dosDate = zipfi->dosDate; - else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate); - } - - zi->ci.flag = 0; - if ((level==8) || (level==9)) - zi->ci.flag |= 2; - if ((level==2)) - zi->ci.flag |= 4; - if ((level==1)) - zi->ci.flag |= 6; - if (password != NULL) - zi->ci.flag |= 1; - - zi->ci.crc32 = 0; - zi->ci.method = method; - zi->ci.encrypt = 0; - zi->ci.stream_initialised = 0; - zi->ci.pos_in_buffered_data = 0; - zi->ci.raw = raw; - zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ; - zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + - size_extrafield_global + size_comment; - zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader); - - ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); - /* version info */ - ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2); - ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); - ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); - ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); - ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); - ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ - ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ - ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ - ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); - ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); - ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); - ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ - - if (zipfi==NULL) - ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); - else - ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); - - if (zipfi==NULL) - ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); - else - ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); - - ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4); - - for (i=0;ici.central_header+SIZECENTRALHEADER+i) = *(filename+i); - - for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+i) = - *(((const char*)extrafield_global)+i); - - for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+ - size_extrafield_global+i) = *(comment+i); - if (zi->ci.central_header == NULL) - return ZIP_INTERNALERROR; - - /* write the local header */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4); - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2); - - if ((err==ZIP_OK) && (size_filename>0)) - if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) - err = ZIP_ERRNO; - - if ((err==ZIP_OK) && (size_extrafield_local>0)) - if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local) - !=size_extrafield_local) - err = ZIP_ERRNO; - - zi->ci.stream.avail_in = (uInt)0; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - zi->ci.stream.total_in = 0; - zi->ci.stream.total_out = 0; - - if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - { - zi->ci.stream.zalloc = (alloc_func)0; - zi->ci.stream.zfree = (free_func)0; - zi->ci.stream.opaque = (voidpf)0; - - if (windowBits>0) - windowBits = -windowBits; - - err = deflateInit2(&zi->ci.stream, level, - Z_DEFLATED, windowBits, memLevel, strategy); - - if (err==Z_OK) - zi->ci.stream_initialised = 1; - } -# ifndef NOCRYPT - zi->ci.crypt_header_size = 0; - if ((err==Z_OK) && (password != NULL)) - { - unsigned char bufHead[RAND_HEAD_LEN]; - unsigned int sizeHead; - zi->ci.encrypt = 1; - zi->ci.pcrc_32_tab = get_crc_table(); - /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ - - sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); - zi->ci.crypt_header_size = sizeHead; - - if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) - err = ZIP_ERRNO; - } -# endif - - if (err==Z_OK) - zi->in_opened_file_inzip = 1; - return err; -} - -extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw) - zipFile file; - const char* filename; - const zip_fileinfo* zipfi; - const void* extrafield_local; - uInt size_extrafield_local; - const void* extrafield_global; - uInt size_extrafield_global; - const char* comment; - int method; - int level; - int raw; -{ - return zipOpenNewFileInZip3 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - NULL, 0); -} - -extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level) - zipFile file; - const char* filename; - const zip_fileinfo* zipfi; - const void* extrafield_local; - uInt size_extrafield_local; - const void* extrafield_global; - uInt size_extrafield_global; - const char* comment; - int method; - int level; -{ - return zipOpenNewFileInZip2 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, 0); -} - -local int zipFlushWriteBuffer(zi) - zip_internal* zi; -{ - int err=ZIP_OK; - - if (zi->ci.encrypt != 0) - { -#ifndef NOCRYPT - uInt i; - int t; - for (i=0;ici.pos_in_buffered_data;i++) - zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, - zi->ci.buffered_data[i],t); -#endif - } - if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) - !=zi->ci.pos_in_buffered_data) - err = ZIP_ERRNO; - zi->ci.pos_in_buffered_data = 0; - return err; -} - -extern int ZEXPORT zipWriteInFileInZip (file, buf, len) - zipFile file; - const void* buf; - unsigned len; -{ - zip_internal* zi; - int err=ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 0) - return ZIP_PARAMERROR; - - zi->ci.stream.next_in = (void*)buf; - zi->ci.stream.avail_in = len; - zi->ci.crc32 = crc32(zi->ci.crc32,buf,len); - - while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) - { - if (zi->ci.stream.avail_out == 0) - { - if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) - err = ZIP_ERRNO; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - } - - - if(err != ZIP_OK) - break; - - if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - { - uLong uTotalOutBefore = zi->ci.stream.total_out; - err=deflate(&zi->ci.stream, Z_NO_FLUSH); - zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; - - } - else - { - uInt copy_this,i; - if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) - copy_this = zi->ci.stream.avail_in; - else - copy_this = zi->ci.stream.avail_out; - for (i=0;ici.stream.next_out)+i) = - *(((const char*)zi->ci.stream.next_in)+i); - { - zi->ci.stream.avail_in -= copy_this; - zi->ci.stream.avail_out-= copy_this; - zi->ci.stream.next_in+= copy_this; - zi->ci.stream.next_out+= copy_this; - zi->ci.stream.total_in+= copy_this; - zi->ci.stream.total_out+= copy_this; - zi->ci.pos_in_buffered_data += copy_this; - } - } - } - - return err; -} - -extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32) - zipFile file; - uLong uncompressed_size; - uLong crc32; -{ - zip_internal* zi; - uLong compressed_size; - int err=ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 0) - return ZIP_PARAMERROR; - zi->ci.stream.avail_in = 0; - - if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - while (err==ZIP_OK) - { - uLong uTotalOutBefore; - if (zi->ci.stream.avail_out == 0) - { - if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) - err = ZIP_ERRNO; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - } - uTotalOutBefore = zi->ci.stream.total_out; - err=deflate(&zi->ci.stream, Z_FINISH); - zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; - } - - if (err==Z_STREAM_END) - err=ZIP_OK; /* this is normal */ - - if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) - if (zipFlushWriteBuffer(zi)==ZIP_ERRNO) - err = ZIP_ERRNO; - - if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - { - err=deflateEnd(&zi->ci.stream); - zi->ci.stream_initialised = 0; - } - - if (!zi->ci.raw) - { - crc32 = (uLong)zi->ci.crc32; - uncompressed_size = (uLong)zi->ci.stream.total_in; - } - compressed_size = (uLong)zi->ci.stream.total_out; -# ifndef NOCRYPT - compressed_size += zi->ci.crypt_header_size; -# endif - - ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ - ziplocal_putValue_inmemory(zi->ci.central_header+20, - compressed_size,4); /*compr size*/ - if (zi->ci.stream.data_type == Z_ASCII) - ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); - ziplocal_putValue_inmemory(zi->ci.central_header+24, - uncompressed_size,4); /*uncompr size*/ - - if (err==ZIP_OK) - err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, - (uLong)zi->ci.size_centralheader); - free(zi->ci.central_header); - - if (err==ZIP_OK) - { - long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); - if (ZSEEK(zi->z_filefunc,zi->filestream, - zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) - err = ZIP_ERRNO; - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ - - if (err==ZIP_OK) /* compressed size, unknown */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); - - if (err==ZIP_OK) /* uncompressed size, unknown */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); - - if (ZSEEK(zi->z_filefunc,zi->filestream, - cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) - err = ZIP_ERRNO; - } - - zi->number_entry ++; - zi->in_opened_file_inzip = 0; - - return err; -} - -extern int ZEXPORT zipCloseFileInZip (file) - zipFile file; -{ - return zipCloseFileInZipRaw (file,0,0); -} - -extern int ZEXPORT zipClose (file, global_comment) - zipFile file; - const char* global_comment; -{ - zip_internal* zi; - int err = 0; - uLong size_centraldir = 0; - uLong centraldir_pos_inzip; - uInt size_global_comment; - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 1) - { - err = zipCloseFileInZip (file); - } - -#ifndef NO_ADDFILEINEXISTINGZIP - if (global_comment==NULL) - global_comment = zi->globalcomment; -#endif - if (global_comment==NULL) - size_global_comment = 0; - else - size_global_comment = (uInt)strlen(global_comment); - - centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); - if (err==ZIP_OK) - { - linkedlist_datablock_internal* ldi = zi->central_dir.first_block ; - while (ldi!=NULL) - { - if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) - if (ZWRITE(zi->z_filefunc,zi->filestream, - ldi->data,ldi->filled_in_this_block) - !=ldi->filled_in_this_block ) - err = ZIP_ERRNO; - - size_centraldir += ldi->filled_in_this_block; - ldi = ldi->next_datablock; - } - } - free_datablock(zi->central_dir.first_block); - - if (err==ZIP_OK) /* Magic End */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); - - if (err==ZIP_OK) /* number of this disk */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); - - if (err==ZIP_OK) /* number of the disk with the start of the central directory */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); - - if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); - - if (err==ZIP_OK) /* total number of entries in the central dir */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); - - if (err==ZIP_OK) /* size of the central directory */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); - - if (err==ZIP_OK) /* offset of start of central directory with respect to the - starting disk number */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream, - (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); - - if (err==ZIP_OK) /* zipfile comment length */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); - - if ((err==ZIP_OK) && (size_global_comment>0)) - if (ZWRITE(zi->z_filefunc,zi->filestream, - global_comment,size_global_comment) != size_global_comment) - err = ZIP_ERRNO; - - if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0) - if (err == ZIP_OK) - err = ZIP_ERRNO; - -#ifndef NO_ADDFILEINEXISTINGZIP - TRYFREE(zi->globalcomment); -#endif - TRYFREE(zi); - - return err; -} diff --git a/core/lib/Zip.h b/core/lib/Zip.h deleted file mode 100755 index cd38b67..0000000 --- a/core/lib/Zip.h +++ /dev/null @@ -1,235 +0,0 @@ -/* zip.h -- IO for compress .zip files using zlib - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - This unzip package allow creates .ZIP file, compatible with PKZip 2.04g - WinZip, InfoZip tools and compatible. - Multi volume ZipFile (span) are not supported. - Encryption compatible with pkzip 2.04g only supported - Old compressions used by old PKZip 1.x are not supported - - For uncompress .zip file, look at unzip.h - - - I WAIT FEEDBACK at mail info@winimage.com - Visit also http://www.winimage.com/zLibDll/unzip.html for evolution - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - -*/ - -/* for more info about .ZIP format, see - http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip - http://www.info-zip.org/pub/infozip/doc/ - PkWare has also a specification at : - ftp://ftp.pkware.com/probdesc.zip -*/ - -#ifndef _zip_H -#define _zip_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -#include "ioapi.h" -#endif - -#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagzipFile__ { int unused; } zipFile__; -typedef zipFile__ *zipFile; -#else -typedef voidp zipFile; -#endif - -#define ZIP_OK (0) -#define ZIP_EOF (0) -#define ZIP_ERRNO (Z_ERRNO) -#define ZIP_PARAMERROR (-102) -#define ZIP_BADZIPFILE (-103) -#define ZIP_INTERNALERROR (-104) - -#ifndef DEF_MEM_LEVEL -# if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -# else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -# endif -#endif -/* default memLevel */ - -/* tm_zip contain date/time info */ -typedef struct tm_zip_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_zip; - -typedef struct -{ - tm_zip tmz_date; /* date in understandable format */ - uLong dosDate; /* if dos_date == 0, tmu_date is used */ -/* uLong flag; */ /* general purpose bit flag 2 bytes */ - - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ -} zip_fileinfo; - -typedef const char* zipcharpc; - - -#define APPEND_STATUS_CREATE (0) -#define APPEND_STATUS_CREATEAFTER (1) -#define APPEND_STATUS_ADDINZIP (2) - -extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); -/* - Create a zipfile. - pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on - an Unix computer "zlib/zlib113.zip". - if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip - will be created at the end of the file. - (useful if the file contain a self extractor code) - if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will - add files in existing zip (be sure you don't add file that doesn't exist) - If the zipfile cannot be opened, the return value is NULL. - Else, the return value is a zipFile Handle, usable with other function - of this zip package. -*/ - -/* Note : there is no delete function into a zipfile. - If you want delete file into a zipfile, you must open a zipfile, and create another - Of couse, you can use RAW reading and writing to copy the file you did not want delte -*/ - -extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, - int append, - zipcharpc* globalcomment, - zlib_filefunc_def* pzlib_filefunc_def)); - -extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level)); -/* - Open a file in the ZIP for writing. - filename : the filename in zip (if NULL, '-' without quote will be used - *zipfi contain supplemental information - if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local - contains the extrafield data the the local header - if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global - contains the extrafield data the the local header - if comment != NULL, comment contain the comment string - method contain the compression method (0 for store, Z_DEFLATED for deflate) - level contain the level of compression (can be Z_DEFAULT_COMPRESSION) -*/ - - -extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw)); - -/* - Same than zipOpenNewFileInZip, except if raw=1, we write raw file - */ - -extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int windowBits, - int memLevel, - int strategy, - const char* password, - uLong crcForCtypting)); - -/* - Same than zipOpenNewFileInZip2, except - windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 - password : crypting password (NULL for no crypting) - crcForCtypting : crc of file to compress (needed for crypting) - */ - - -extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, - const void* buf, - unsigned len)); -/* - Write data in the zipfile -*/ - -extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); -/* - Close the current file in the zipfile -*/ - -extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, - uLong uncompressed_size, - uLong crc32)); -/* - Close the current file in the zipfile, for fiel opened with - parameter raw=1 in zipOpenNewFileInZip2 - uncompressed_size and crc32 are value for the uncompressed size -*/ - -extern int ZEXPORT zipClose OF((zipFile file, - const char* global_comment)); -/* - Close the zipfile -*/ - -#ifdef __cplusplus -} -#endif - -#endif /* _zip_H */ diff --git a/core/lib/Zlib.h b/core/lib/Zlib.h deleted file mode 100755 index d54ac94..0000000 --- a/core/lib/Zlib.h +++ /dev/null @@ -1,1200 +0,0 @@ -/* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.1, November 17th, 2003 - - Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt - (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). -*/ - -#ifndef ZLIB_H -#define ZLIB_H - -#include "zconf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ZLIB_VERSION "1.2.1" -#define ZLIB_VERNUM 0x1210 - -/* - The 'zlib' compression library provides in-memory compression and - decompression functions, including integrity checks of the uncompressed - data. This version of the library supports only one compression method - (deflation) but other algorithms will be added later and will have the same - stream interface. - - Compression can be done in a single step if the buffers are large - enough (for example if an input file is mmap'ed), or can be done by - repeated calls of the compression function. In the latter case, the - application must provide more input and/or consume the output - (providing more output space) before each call. - - The compressed data format used by the in-memory functions is the zlib - format, which is a zlib wrapper documented in RFC 1950, wrapped around a - deflate stream, which is itself documented in RFC 1951. - - The library also supports reading and writing files in gzip (.gz) format - with an interface similar to that of stdio using the functions that start - with "gz". The gzip format is different from the zlib format. gzip is a - gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. - - The zlib format was designed to be compact and fast for use in memory - and on communications channels. The gzip format was designed for single- - file compression on file systems, has a larger header than zlib to maintain - directory information, and uses a different, slower check method than zlib. - - This library does not provide any functions to write gzip files in memory. - However such functions could be easily written using zlib's deflate function, - the documentation in the gzip RFC, and the examples in gzio.c. - - The library does not install any signal handler. The decoder checks - the consistency of the compressed data, so the library should never - crash even in case of corrupted input. -*/ - -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); - -struct internal_state; - -typedef struct z_stream_s { - Bytef *next_in; /* next input byte */ - uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total nb of input bytes read so far */ - - Bytef *next_out; /* next output byte should be put there */ - uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total nb of bytes output so far */ - - char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ - - alloc_func zalloc; /* used to allocate the internal state */ - free_func zfree; /* used to free the internal state */ - voidpf opaque; /* private data object passed to zalloc and zfree */ - - int data_type; /* best guess about the data type: ascii or binary */ - uLong adler; /* adler32 value of the uncompressed data */ - uLong reserved; /* reserved for future use */ -} z_stream; - -typedef z_stream FAR *z_streamp; - -/* - The application must update next_in and avail_in when avail_in has - dropped to zero. It must update next_out and avail_out when avail_out - has dropped to zero. The application must initialize zalloc, zfree and - opaque before calling the init function. All other fields are set by the - compression library and must not be updated by the application. - - The opaque value provided by the application will be passed as the first - parameter for calls of zalloc and zfree. This can be useful for custom - memory management. The compression library attaches no meaning to the - opaque value. - - zalloc must return Z_NULL if there is not enough memory for the object. - If zlib is used in a multi-threaded application, zalloc and zfree must be - thread safe. - - On 16-bit systems, the functions zalloc and zfree must be able to allocate - exactly 65536 bytes, but will not be required to allocate more than this - if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, - pointers returned by zalloc for objects of exactly 65536 bytes *must* - have their offset normalized to zero. The default allocation function - provided by this library ensures this (see zutil.c). To reduce memory - requirements and avoid any allocation of 64K objects, at the expense of - compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h). - - The fields total_in and total_out can be used for statistics or - progress reports. After compression, total_in holds the total size of - the uncompressed data and may be saved for use in the decompressor - (particularly if the decompressor wants to decompress everything in - a single step). -*/ - - /* constants */ - -#define Z_NO_FLUSH 0 -#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */ -#define Z_SYNC_FLUSH 2 -#define Z_FULL_FLUSH 3 -#define Z_FINISH 4 -#define Z_BLOCK 5 -/* Allowed flush values; see deflate() and inflate() below for details */ - -#define Z_OK 0 -#define Z_STREAM_END 1 -#define Z_NEED_DICT 2 -#define Z_ERRNO (-1) -#define Z_STREAM_ERROR (-2) -#define Z_DATA_ERROR (-3) -#define Z_MEM_ERROR (-4) -#define Z_BUF_ERROR (-5) -#define Z_VERSION_ERROR (-6) -/* Return codes for the compression/decompression functions. Negative - * values are errors, positive values are used for special but normal events. - */ - -#define Z_NO_COMPRESSION 0 -#define Z_BEST_SPEED 1 -#define Z_BEST_COMPRESSION 9 -#define Z_DEFAULT_COMPRESSION (-1) -/* compression levels */ - -#define Z_FILTERED 1 -#define Z_HUFFMAN_ONLY 2 -#define Z_RLE 3 -#define Z_DEFAULT_STRATEGY 0 -/* compression strategy; see deflateInit2() below for details */ - -#define Z_BINARY 0 -#define Z_ASCII 1 -#define Z_UNKNOWN 2 -/* Possible values of the data_type field (though see inflate()) */ - -#define Z_DEFLATED 8 -/* The deflate compression method (the only one supported in this version) */ - -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ - -#define zlib_version zlibVersion() -/* for compatibility with versions < 1.0.2 */ - - /* basic functions */ - -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); -/* The application can compare zlibVersion and ZLIB_VERSION for consistency. - If the first character differs, the library code actually used is - not compatible with the zlib.h header file used by the application. - This check is automatically made by deflateInit and inflateInit. - */ - -/* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); - - Initializes the internal stream state for compression. The fields - zalloc, zfree and opaque must be initialized before by the caller. - If zalloc and zfree are set to Z_NULL, deflateInit updates them to - use default allocation functions. - - The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: - 1 gives best speed, 9 gives best compression, 0 gives no compression at - all (the input data is simply copied a block at a time). - Z_DEFAULT_COMPRESSION requests a default compromise between speed and - compression (currently equivalent to level 6). - - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if level is not a valid compression level, - Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible - with the version assumed by the caller (ZLIB_VERSION). - msg is set to null if there is no error message. deflateInit does not - perform any compression: this will be done by deflate(). -*/ - - -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); -/* - deflate compresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce some - output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. deflate performs one or both of the - following actions: - - - Compress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in and avail_in are updated and - processing will resume at this point for the next call of deflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. This action is forced if the parameter flush is non zero. - Forcing flush frequently degrades the compression ratio, so this parameter - should be set only when necessary (in interactive applications). - Some output may be provided even if flush is not set. - - Before the call of deflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating avail_in or avail_out accordingly; avail_out - should never be zero before the call. The application can consume the - compressed output when it wants, for example when the output buffer is full - (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK - and with zero avail_out, it must be called again after making room in the - output buffer because there might be more output pending. - - If the parameter flush is set to Z_SYNC_FLUSH, all pending output is - flushed to the output buffer and the output is aligned on a byte boundary, so - that the decompressor can get all input data available so far. (In particular - avail_in is zero after the call if enough output space has been provided - before the call.) Flushing may degrade compression for some compression - algorithms and so it should be used only when necessary. - - If flush is set to Z_FULL_FLUSH, all output is flushed as with - Z_SYNC_FLUSH, and the compression state is reset so that decompression can - restart from this point if previous compressed data has been damaged or if - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - the compression. - - If deflate returns with avail_out == 0, this function must be called again - with the same value of the flush parameter and more output space (updated - avail_out), until the flush is complete (deflate returns with non-zero - avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. - - If the parameter flush is set to Z_FINISH, pending input is processed, - pending output is flushed and deflate returns with Z_STREAM_END if there - was enough output space; if deflate returns with Z_OK, this function must be - called again with Z_FINISH and more output space (updated avail_out) but no - more input data, until it returns with Z_STREAM_END or an error. After - deflate has returned Z_STREAM_END, the only possible operations on the - stream are deflateReset or deflateEnd. - - Z_FINISH can be used immediately after deflateInit if all the compression - is to be done in a single step. In this case, avail_out must be at least - the value returned by deflateBound (see below). If deflate does not return - Z_STREAM_END, then it must be called again as described above. - - deflate() sets strm->adler to the adler32 checksum of all input read - so far (that is, total_in bytes). - - deflate() may update data_type if it can make a good guess about - the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered - binary. This field is only for information purposes and does not affect - the compression algorithm in any manner. - - deflate() returns Z_OK if some progress has been made (more input - processed or more output produced), Z_STREAM_END if all input has been - consumed and all output has been produced (only when flush is set to - Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible - (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not - fatal, and deflate() can be called again with more input and more output - space to continue compressing. -*/ - - -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. - - deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the - stream state was inconsistent, Z_DATA_ERROR if the stream was freed - prematurely (some input or output was discarded). In the error case, - msg may be set but then points to a static string (which must not be - deallocated). -*/ - - -/* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); - - Initializes the internal stream state for decompression. The fields - next_in, avail_in, zalloc, zfree and opaque must be initialized before by - the caller. If next_in is not Z_NULL and avail_in is large enough (the exact - value depends on the compression method), inflateInit determines the - compression method from the zlib header and allocates all data structures - accordingly; otherwise the allocation will be deferred to the first call of - inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to - use default allocation functions. - - inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller. msg is set to null if there is no error - message. inflateInit does not perform any decompression apart from reading - the zlib header if present: this will be done by inflate(). (So next_in and - avail_in may be modified, but next_out and avail_out are unchanged.) -*/ - - -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); -/* - inflate decompresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce - some output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. inflate performs one or both of the - following actions: - - - Decompress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in is updated and processing - will resume at this point for the next call of inflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. inflate() provides as much output as possible, until there - is no more input data or no more space in the output buffer (see below - about the flush parameter). - - Before the call of inflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming - more output, and updating the next_* and avail_* values accordingly. - The application can consume the uncompressed output when it wants, for - example when the output buffer is full (avail_out == 0), or after each - call of inflate(). If inflate returns Z_OK and with zero avail_out, it - must be called again after making room in the output buffer because there - might be more output pending. - - The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, - Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much - output as possible to the output buffer. Z_BLOCK requests that inflate() stop - if and when it get to the next deflate block boundary. When decoding the zlib - or gzip format, this will cause inflate() to return immediately after the - header and before the first block. When doing a raw inflate, inflate() will - go ahead and process the first block, and will return when it gets to the end - of that block, or when it runs out of data. - - The Z_BLOCK option assists in appending to or combining deflate streams. - Also to assist in this, on return inflate() will set strm->data_type to the - number of unused bits in the last byte taken from strm->next_in, plus 64 - if inflate() is currently decoding the last block in the deflate stream, - plus 128 if inflate() returned immediately after decoding an end-of-block - code or decoding the complete header up to just before the first byte of the - deflate stream. The end-of-block will not be indicated until all of the - uncompressed data from that block has been written to strm->next_out. The - number of unused bits may in general be greater than seven, except when - bit 7 of data_type is set, in which case the number of unused bits will be - less than eight. - - inflate() should normally be called until it returns Z_STREAM_END or an - error. However if all decompression is to be performed in a single step - (a single call of inflate), the parameter flush should be set to - Z_FINISH. In this case all pending input is processed and all pending - output is flushed; avail_out must be large enough to hold all the - uncompressed data. (The size of the uncompressed data may have been saved - by the compressor for this purpose.) The next operation on this stream must - be inflateEnd to deallocate the decompression state. The use of Z_FINISH - is never required, but can be used to inform inflate that a faster approach - may be used for the single inflate() call. - - In this implementation, inflate() always flushes as much output as - possible to the output buffer, and always uses the faster approach on the - first call. So the only effect of the flush parameter in this implementation - is on the return value of inflate(), as noted below, or when it returns early - because Z_BLOCK is used. - - If a preset dictionary is needed after this call (see inflateSetDictionary - below), inflate sets strm-adler to the adler32 checksum of the dictionary - chosen by the compressor and returns Z_NEED_DICT; otherwise it sets - strm->adler to the adler32 checksum of all output produced so far (that is, - total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described - below. At the end of the stream, inflate() checks that its computed adler32 - checksum is equal to that saved by the compressor and returns Z_STREAM_END - only if the checksum is correct. - - inflate() will decompress and check either zlib-wrapped or gzip-wrapped - deflate data. The header type is detected automatically. Any information - contained in the gzip header is not retained, so applications that need that - information should instead use raw inflate, see inflateInit2() below, or - inflateBack() and perform their own processing of the gzip header and - trailer. - - inflate() returns Z_OK if some progress has been made (more input processed - or more output produced), Z_STREAM_END if the end of the compressed data has - been reached and all uncompressed output has been produced, Z_NEED_DICT if a - preset dictionary is needed at this point, Z_DATA_ERROR if the input data was - corrupted (input stream not conforming to the zlib format or incorrect check - value), Z_STREAM_ERROR if the stream structure was inconsistent (for example - if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory, - Z_BUF_ERROR if no progress is possible or if there was not enough room in the - output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and - inflate() can be called again with more input and more output space to - continue decompressing. If Z_DATA_ERROR is returned, the application may then - call inflateSync() to look for a good compression block if a partial recovery - of the data is desired. -*/ - - -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any - pending output. - - inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state - was inconsistent. In the error case, msg may be set but then points to a - static string (which must not be deallocated). -*/ - - /* Advanced functions */ - -/* - The following functions are needed only in some special applications. -*/ - -/* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); - - This is another version of deflateInit with more compression options. The - fields next_in, zalloc, zfree and opaque must be initialized before by - the caller. - - The method parameter is the compression method. It must be Z_DEFLATED in - this version of the library. - - The windowBits parameter is the base two logarithm of the window size - (the size of the history buffer). It should be in the range 8..15 for this - version of the library. Larger values of this parameter result in better - compression at the expense of memory usage. The default value is 15 if - deflateInit is used instead. - - windowBits can also be -8..-15 for raw deflate. In this case, -windowBits - determines the window size. deflate() will then generate raw deflate data - with no zlib header or trailer, and will not compute an adler32 check value. - - windowBits can also be greater than 15 for optional gzip encoding. Add - 16 to windowBits to write a simple gzip header and trailer around the - compressed data instead of a zlib wrapper. The gzip header will have no - file name, no extra data, no comment, no modification time (set to zero), - no header crc, and the operating system will be set to 255 (unknown). - - The memLevel parameter specifies how much memory should be allocated - for the internal compression state. memLevel=1 uses minimum memory but - is slow and reduces compression ratio; memLevel=9 uses maximum memory - for optimal speed. The default value is 8. See zconf.h for total memory - usage as a function of windowBits and memLevel. - - The strategy parameter is used to tune the compression algorithm. Use the - value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a - filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no - string match), or Z_RLE to limit match distances to one (run-length - encoding). Filtered data consists mostly of small values with a somewhat - random distribution. In this case, the compression algorithm is tuned to - compress them better. The effect of Z_FILTERED is to force more Huffman - coding and less string matching; it is somewhat intermediate between - Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as - Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy - parameter only affects the compression ratio but not the correctness of the - compressed output even if it is not set appropriately. - - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid - method). msg is set to null if there is no error message. deflateInit2 does - not perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the compression dictionary from the given byte sequence - without producing any compressed output. This function must be called - immediately after deflateInit, deflateInit2 or deflateReset, before any - call of deflate. The compressor and decompressor must use exactly the same - dictionary (see inflateSetDictionary). - - The dictionary should consist of strings (byte sequences) that are likely - to be encountered later in the data to be compressed, with the most commonly - used strings preferably put towards the end of the dictionary. Using a - dictionary is most useful when the data to be compressed is short and can be - predicted with good accuracy; the data can then be compressed better than - with the default empty dictionary. - - Depending on the size of the compression data structures selected by - deflateInit or deflateInit2, a part of the dictionary may in effect be - discarded, for example if the dictionary is larger than the window size in - deflate or deflate2. Thus the strings most likely to be useful should be - put at the end of the dictionary, not at the front. - - Upon return of this function, strm->adler is set to the adler32 value - of the dictionary; the decompressor may later use this value to determine - which dictionary has been used by the compressor. (The adler32 value - applies to the whole dictionary even if only a subset of the dictionary is - actually used by the compressor.) If a raw deflate was requested, then the - adler32 value is not computed and strm->adler is not set. - - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is - inconsistent (for example if deflate has already been called for this stream - or if the compression method is bsort). deflateSetDictionary does not - perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when several compression strategies will be - tried, for example when there are several ways of pre-processing the input - data with a filter. The streams that will be discarded should then be freed - by calling deflateEnd. Note that deflateCopy duplicates the internal - compression state which can be quite large, so this strategy is slow and - can consume lots of memory. - - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); -/* - This function is equivalent to deflateEnd followed by deflateInit, - but does not free and reallocate all the internal compression state. - The stream will keep the same compression level and any other attributes - that may have been set by deflateInit2. - - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). -*/ - -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); -/* - Dynamically update the compression level and compression strategy. The - interpretation of level and strategy is as in deflateInit2. This can be - used to switch between compression and straight copy of the input data, or - to switch to a different kind of input data requiring a different - strategy. If the compression level is changed, the input available so far - is compressed with the old level (and may be flushed); the new level will - take effect only at the next call of deflate(). - - Before the call of deflateParams, the stream state must be set as for - a call of deflate(), since the currently available input may have to - be compressed and flushed. In particular, strm->avail_out must be non-zero. - - deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR - if strm->avail_out was zero. -*/ - -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); -/* - deflateBound() returns an upper bound on the compressed size after - deflation of sourceLen bytes. It must be called after deflateInit() - or deflateInit2(). This would be used to allocate an output buffer - for deflation in a single pass, and so would be called before deflate(). -*/ - -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, - int bits, - int value)); -/* - deflatePrime() inserts bits in the deflate output stream. The intent - is that this function is used to start off the deflate output with the - bits leftover from a previous deflate stream when appending to it. As such, - this function can only be used for raw deflate, and must be used before the - first deflate() call after a deflateInit2() or deflateReset(). bits must be - less than or equal to 16, and that many of the least significant bits of - value will be inserted in the output. - - deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -/* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); - - This is another version of inflateInit with an extra parameter. The - fields next_in, avail_in, zalloc, zfree and opaque must be initialized - before by the caller. - - The windowBits parameter is the base two logarithm of the maximum window - size (the size of the history buffer). It should be in the range 8..15 for - this version of the library. The default value is 15 if inflateInit is used - instead. windowBits must be greater than or equal to the windowBits value - provided to deflateInit2() while compressing, or it must be equal to 15 if - deflateInit2() was not used. If a compressed stream with a larger window - size is given as input, inflate() will return with the error code - Z_DATA_ERROR instead of trying to allocate a larger window. - - windowBits can also be -8..-15 for raw inflate. In this case, -windowBits - determines the window size. inflate() will then process raw deflate data, - not looking for a zlib or gzip header, not generating a check value, and not - looking for any check values for comparison at the end of the stream. This - is for use with other formats that use the deflate compressed data format - such as zip. Those formats provide their own check values. If a custom - format is developed using the raw deflate format for compressed data, it is - recommended that a check value such as an adler32 or a crc32 be applied to - the uncompressed data as is done in the zlib, gzip, and zip formats. For - most applications, the zlib format should be used as is. Note that comments - above on the use in deflateInit2() applies to the magnitude of windowBits. - - windowBits can also be greater than 15 for optional gzip decoding. Add - 32 to windowBits to enable zlib and gzip decoding with automatic header - detection, or add 16 to decode only the gzip format (the zlib format will - return a Z_DATA_ERROR). - - inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative - memLevel). msg is set to null if there is no error message. inflateInit2 - does not perform any decompression apart from reading the zlib header if - present: this will be done by inflate(). (So next_in and avail_in may be - modified, but next_out and avail_out are unchanged.) -*/ - -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate - if this call returned Z_NEED_DICT. The dictionary chosen by the compressor - can be determined from the adler32 value returned by this call of - inflate. The compressor and decompressor must use exactly the same - dictionary (see deflateSetDictionary). - - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - parameter is invalid (such as NULL dictionary) or the stream state is - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - expected one (incorrect adler32 value). inflateSetDictionary does not - perform any decompression: this will be done by subsequent calls of - inflate(). -*/ - -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); -/* - Skips invalid compressed data until a full flush point (see above the - description of deflate with Z_FULL_FLUSH) can be found, or until all - available input is skipped. No output is provided. - - inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR - if no more input was provided, Z_DATA_ERROR if no flush point has been found, - or Z_STREAM_ERROR if the stream structure was inconsistent. In the success - case, the application may save the current current value of total_in which - indicates where valid compressed data was found. In the error case, the - application may repeatedly call inflateSync, providing more input each time, - until success or end of the input data. -*/ - -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when randomly accessing a large stream. The - first pass through the stream can periodically record the inflate state, - allowing restarting inflate at those points when randomly accessing the - stream. - - inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); -/* - This function is equivalent to inflateEnd followed by inflateInit, - but does not free and reallocate all the internal decompression state. - The stream will keep attributes that may have been set by inflateInit2. - - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being NULL). -*/ - -/* -ZEXTERN int ZEXPORT inflateBackInit OF((z_stream FAR *strm, int windowBits, - unsigned char FAR *window)); - - Initialize the internal stream state for decompression using inflateBack() - calls. The fields zalloc, zfree and opaque in strm must be initialized - before the call. If zalloc and zfree are Z_NULL, then the default library- - derived memory allocation routines are used. windowBits is the base two - logarithm of the window size, in the range 8..15. window is a caller - supplied buffer of that size. Except for special applications where it is - assured that deflate was used with small window sizes, windowBits must be 15 - and a 32K byte window must be supplied to be able to decompress general - deflate streams. - - See inflateBack() for the usage of these routines. - - inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of - the paramaters are invalid, Z_MEM_ERROR if the internal state could not - be allocated, or Z_VERSION_ERROR if the version of the library does not - match the version of the header file. -*/ - -typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); - -ZEXTERN int ZEXPORT inflateBack OF((z_stream FAR *strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); -/* - inflateBack() does a raw inflate with a single call using a call-back - interface for input and output. This is more efficient than inflate() for - file i/o applications in that it avoids copying between the output and the - sliding window by simply making the window itself the output buffer. This - function trusts the application to not change the output buffer passed by - the output function, at least until inflateBack() returns. - - inflateBackInit() must be called first to allocate the internal state - and to initialize the state with the user-provided window buffer. - inflateBack() may then be used multiple times to inflate a complete, raw - deflate stream with each call. inflateBackEnd() is then called to free - the allocated state. - - A raw deflate stream is one with no zlib or gzip header or trailer. - This routine would normally be used in a utility that reads zip or gzip - files and writes out uncompressed files. The utility would decode the - header and process the trailer on its own, hence this routine expects - only the raw deflate stream to decompress. This is different from the - normal behavior of inflate(), which expects either a zlib or gzip header and - trailer around the deflate stream. - - inflateBack() uses two subroutines supplied by the caller that are then - called by inflateBack() for input and output. inflateBack() calls those - routines until it reads a complete deflate stream and writes out all of the - uncompressed data, or until it encounters an error. The function's - parameters and return types are defined above in the in_func and out_func - typedefs. inflateBack() will call in(in_desc, &buf) which should return the - number of bytes of provided input, and a pointer to that input in buf. If - there is no input available, in() must return zero--buf is ignored in that - case--and inflateBack() will return a buffer error. inflateBack() will call - out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() - should return zero on success, or non-zero on failure. If out() returns - non-zero, inflateBack() will return with an error. Neither in() nor out() - are permitted to change the contents of the window provided to - inflateBackInit(), which is also the buffer that out() uses to write from. - The length written by out() will be at most the window size. Any non-zero - amount of input may be provided by in(). - - For convenience, inflateBack() can be provided input on the first call by - setting strm->next_in and strm->avail_in. If that input is exhausted, then - in() will be called. Therefore strm->next_in must be initialized before - calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called - immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in - must also be initialized, and then if strm->avail_in is not zero, input will - initially be taken from strm->next_in[0 .. strm->avail_in - 1]. - - The in_desc and out_desc parameters of inflateBack() is passed as the - first parameter of in() and out() respectively when they are called. These - descriptors can be optionally used to pass any information that the caller- - supplied in() and out() functions need to do their job. - - On return, inflateBack() will set strm->next_in and strm->avail_in to - pass back any unused input that was provided by the last in() call. The - return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR - if in() or out() returned an error, Z_DATA_ERROR if there was a format - error in the deflate stream (in which case strm->msg is set to indicate the - nature of the error), or Z_STREAM_ERROR if the stream was not properly - initialized. In the case of Z_BUF_ERROR, an input or output error can be - distinguished using strm->next_in which will be Z_NULL only if in() returned - an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to - out() returning non-zero. (in() will always be called before out(), so - strm->next_in is assured to be defined if out() returns non-zero.) Note - that inflateBack() cannot return Z_OK. -*/ - -ZEXTERN int ZEXPORT inflateBackEnd OF((z_stream FAR *strm)); -/* - All memory allocated by inflateBackInit() is freed. - - inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream - state was inconsistent. -*/ - -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); -/* Return flags indicating compile-time options. - - Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: - 1.0: size of uInt - 3.2: size of uLong - 5.4: size of voidpf (pointer) - 7.6: size of z_off_t - - Compiler, assembler, and debug options: - 8: DEBUG - 9: ASMV or ASMINF -- use ASM code - 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention - 11: 0 (reserved) - - One-time table building (smaller code, but not thread-safe if true): - 12: BUILDFIXED -- build static block decoding tables when needed - 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed - 14,15: 0 (reserved) - - Library content (indicates missing functionality): - 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking - deflate code when not needed) - 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect - and decode gzip streams (to avoid linking crc code) - 18-19: 0 (reserved) - - Operation variations (changes in library functionality): - 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate - 21: FASTEST -- deflate algorithm with only one, lowest compression level - 22,23: 0 (reserved) - - The sprintf variant used by gzprintf (zero is best): - 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format - 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! - 26: 0 = returns value, 1 = void -- 1 means inferred string length returned - - Remainder: - 27-31: 0 (reserved) - */ - - - /* utility functions */ - -/* - The following utility functions are implemented on top of the - basic stream-oriented functions. To simplify the interface, some - default options are assumed (compression level and memory usage, - standard memory allocation functions). The source code of these - utility functions can easily be modified if you need special options. -*/ - -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Compresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be at least the value returned - by compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed buffer. - This function can be used to compress a whole file at once if the - input file is mmap'ed. - compress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer. -*/ - -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); -/* - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ - -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); -/* - compressBound() returns an upper bound on the compressed size after - compress() or compress2() on sourceLen bytes. It would be used before - a compress() or compress2() call to allocate the destination buffer. -*/ - -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to decompress a whole file at once if the - input file is mmap'ed. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. -*/ - - -typedef voidp gzFile; - -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); -/* - Opens a gzip (.gz) file for reading or writing. The mode parameter - is as in fopen ("rb" or "wb") but can also include a compression level - ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for - Huffman only compression as in "wb1h", or 'R' for run-length encoding - as in "wb1R". (See the description of deflateInit2 for more information - about the strategy parameter.) - - gzopen can be used to read a file which is not in gzip format; in this - case gzread will directly read from the file without decompression. - - gzopen returns NULL if the file could not be opened or if there was - insufficient memory to allocate the (de)compression state; errno - can be checked to distinguish the two cases (if errno is zero, the - zlib error is Z_MEM_ERROR). */ - -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); -/* - gzdopen() associates a gzFile with the file descriptor fd. File - descriptors are obtained from calls like open, dup, creat, pipe or - fileno (in the file has been previously opened with fopen). - The mode parameter is as in gzopen. - The next call of gzclose on the returned gzFile will also close the - file descriptor fd, just like fclose(fdopen(fd), mode) closes the file - descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode). - gzdopen returns NULL if there was insufficient memory to allocate - the (de)compression state. -*/ - -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); -/* - Dynamically update the compression level or strategy. See the description - of deflateInit2 for the meaning of these parameters. - gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not - opened for writing. -*/ - -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); -/* - Reads the given number of uncompressed bytes from the compressed file. - If the input file was not in gzip format, gzread copies the given number - of bytes into the buffer. - gzread returns the number of uncompressed bytes actually read (0 for - end of file, -1 for error). */ - -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, - voidpc buf, unsigned len)); -/* - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of uncompressed bytes actually written - (0 in case of error). -*/ - -ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); -/* - Converts, formats, and writes the args to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written (0 in case of error). The number of - uncompressed bytes written is limited to 4095. The caller should assure that - this limit is not exceeded. If it is exceeded, then gzprintf() will return - return an error (0) with nothing written. In this case, there may also be a - buffer overflow with unpredictable consequences, which is possible only if - zlib was compiled with the insecure functions sprintf() or vsprintf() - because the secure snprintf() or vsnprintf() functions were not available. -*/ - -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); -/* - Writes the given null-terminated string to the compressed file, excluding - the terminating null character. - gzputs returns the number of characters written, or -1 in case of error. -*/ - -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); -/* - Reads bytes from the compressed file until len-1 characters are read, or - a newline character is read and transferred to buf, or an end-of-file - condition is encountered. The string is then terminated with a null - character. - gzgets returns buf, or Z_NULL in case of error. -*/ - -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); -/* - Writes c, converted to an unsigned char, into the compressed file. - gzputc returns the value that was written, or -1 in case of error. -*/ - -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); -/* - Reads one byte from the compressed file. gzgetc returns this byte - or -1 in case of end of file or error. -*/ - -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); -/* - Push one character back onto the stream to be read again later. - Only one character of push-back is allowed. gzungetc() returns the - character pushed, or -1 on failure. gzungetc() will fail if a - character has been pushed but not read yet, or if c is -1. The pushed - character will be discarded if the stream is repositioned with gzseek() - or gzrewind(). -*/ - -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); -/* - Flushes all pending output into the compressed file. The parameter - flush is as in the deflate() function. The return value is the zlib - error number (see function gzerror below). gzflush returns Z_OK if - the flush parameter is Z_FINISH and all output could be flushed. - gzflush should be called only when strictly necessary because it can - degrade compression. -*/ - -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); -/* - Sets the starting position for the next gzread or gzwrite on the - given compressed file. The offset represents a number of bytes in the - uncompressed data stream. The whence parameter is defined as in lseek(2); - the value SEEK_END is not supported. - If the file is opened for reading, this function is emulated but can be - extremely slow. If the file is opened for writing, only forward seeks are - supported; gzseek then compresses a sequence of zeroes up to the new - starting position. - - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error, in - particular if the file is opened for writing and the new starting position - would be before the current position. -*/ - -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); -/* - Rewinds the given file. This function is supported only for reading. - - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) -*/ - -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); -/* - Returns the starting position for the next gzread or gzwrite on the - given compressed file. This position represents a number of bytes in the - uncompressed data stream. - - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) -*/ - -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); -/* - Returns 1 when EOF has previously been detected reading the given - input stream, otherwise zero. -*/ - -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); -/* - Flushes all pending output if necessary, closes the compressed file - and deallocates all the (de)compression state. The return value is the zlib - error number (see function gzerror below). -*/ - -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); -/* - Returns the error message for the last error which occurred on the - given compressed file. errnum is set to zlib error number. If an - error occurred in the file system and not in the compression library, - errnum is set to Z_ERRNO and the application may consult errno - to get the exact error code. -*/ - -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); -/* - Clears the error and end-of-file flags for file. This is analogous to the - clearerr() function in stdio. This is useful for continuing to read a gzip - file that is being written concurrently. -*/ - - /* checksum functions */ - -/* - These functions are not related to compression but are exported - anyway because they might be useful in applications using the - compression library. -*/ - -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); - -/* - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is NULL, this function returns - the required initial value for the checksum. - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. Usage example: - - uLong adler = adler32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); -*/ - -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); -/* - Update a running crc with the bytes buf[0..len-1] and return the updated - crc. If buf is NULL, this function returns the required initial value - for the crc. Pre- and post-conditioning (one's complement) is performed - within this function so it shouldn't be done by the application. - Usage example: - - uLong crc = crc32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - crc = crc32(crc, buffer, length); - } - if (crc != original_crc) error(); -*/ - - - /* various hacks, don't look :) */ - -/* deflateInit and inflateInit are macros to allow checking the zlib version - * and the compiler's view of z_stream: - */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_stream FAR *strm, int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size)); -#define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) -#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) -#define inflateBackInit(strm, windowBits, window) \ - inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, sizeof(z_stream)) - - -#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) - struct internal_state {int dummy;}; /* hack for buggy compilers */ -#endif - -ZEXTERN const char * ZEXPORT zError OF((int err)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z)); -ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); - -#ifdef __cplusplus -} -#endif - -#endif /* ZLIB_H */ diff --git a/core/lib/miniunz.h b/core/lib/miniunz.h deleted file mode 100755 index 23a3f0f..0000000 --- a/core/lib/miniunz.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 Library 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. - */ -#ifndef MINIUNZ_H -#define MINIUNZ_H - -//! Look for possible filename in zip archive -char *find_possible_filename_in_zip (char *zipfilename, const char* extstr); - -//! Extract file content from zip archive -int extract_file_in_memory (char *zipfilename, char *archivedfile, - size_t * unzipped_size); - -#endif diff --git a/core/lib/unzip.h b/core/lib/unzip.h deleted file mode 100755 index 76692cb..0000000 --- a/core/lib/unzip.h +++ /dev/null @@ -1,275 +0,0 @@ -/* unzip.h -- IO for uncompress .zip files using zlib - Version 0.15 beta, Mar 19th, 1998, - - Copyright (C) 1998 Gilles Vollant - - This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g - WinZip, InfoZip tools and compatible. - Encryption and multi volume ZipFile (span) are not supported. - Old compressions used by old PKZip 1.x are not supported - - THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE - CAN CHANGE IN FUTURE VERSION !! - I WAIT FEEDBACK at mail info@winimage.com - Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - -*/ -/* for more info about .ZIP format, see - ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip - PkWare has also a specification at : - ftp://ftp.pkware.com/probdesc.zip */ - -#ifndef _unz_H -#define _unz_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagunzFile__ { int unused; } unzFile__; -typedef unzFile__ *unzFile; -#else -typedef voidp unzFile; -#endif - - -#define UNZ_OK (0) -#define UNZ_END_OF_LIST_OF_FILE (-100) -#define UNZ_ERRNO (Z_ERRNO) -#define UNZ_EOF (0) -#define UNZ_PARAMERROR (-102) -#define UNZ_BADZIPFILE (-103) -#define UNZ_INTERNALERROR (-104) -#define UNZ_CRCERROR (-105) - -/* tm_unz contain date/time info */ -typedef struct tm_unz_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_unz; - -/* unz_global_info structure contain global data about the ZIPfile - These data comes from the end of central dir */ -typedef struct unz_global_info_s -{ - uLong number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info; - - -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_info_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - uLong compressed_size; /* compressed size 4 bytes */ - uLong uncompressed_size; /* uncompressed size 4 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info; - -extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, - const char* fileName2, - int iCaseSensitivity)); -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) -*/ - - -extern unzFile ZEXPORT unzOpen OF((const char *path)); -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer - "zlib/zlib111.zip". - If the zipfile cannot be opened (file don't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. -*/ - -extern int ZEXPORT unzClose OF((unzFile file)); -/* - Close a ZipFile opened with unzipOpen. - If there is files inside the .Zip opened with unzOpenCurrentFile (see later), - these files MUST be closed with unzipCloseCurrentFile before call unzipClose. - return UNZ_OK if there is no problem. */ - -extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, - unz_global_info *pglobal_info)); -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ - - -extern int ZEXPORT unzGetGlobalComment OF((unzFile file, - char *szComment, - uLong uSizeBuf)); -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ - - -/***************************************************************************/ -/* Unzip package allow you browse the directory of the zipfile */ - -extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ - -extern int ZEXPORT unzGoToNextFile OF((unzFile file)); -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ - -extern int ZEXPORT unzLocateFile OF((unzFile file, - const char *szFileName, - int iCaseSensitivity)); -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ - - -extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, - unz_file_info *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); -/* - Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain somes info about - the current file - if szFileName!=NULL, the filemane string will be copied in szFileName - (fileNameBufferSize is the size of the buffer) - if extraField!=NULL, the extra field information will be copied in extraField - (extraFieldBufferSize is the size of the buffer). - This is the Central-header version of the extra field - if szComment!=NULL, the comment string of the file will be copied in szComment - (commentBufferSize is the size of the buffer) -*/ - -/***************************************************************************/ -/* for reading the content of the current zipfile, you can open it, read data - from it, and close it (you can close it before reading all the file) - */ - -extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); -/* - Open for reading data the current file in the zipfile. - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); -/* - Close the file in zip opened with unzOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ - - -extern int ZEXPORT unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read bytes from the current file (opened by unzOpenCurrentFile) - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ - -extern z_off_t ZEXPORT unztell OF((unzFile file)); -/* - Give the current position in uncompressed data -*/ - -extern int ZEXPORT unzeof OF((unzFile file)); -/* - return 1 if the end of file was reached, 0 elsewhere -*/ - -extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ - -#ifdef __cplusplus -} -#endif - -#endif /* _unz_H */ diff --git a/src/Bios.c b/src/Bios.c new file mode 100644 index 0000000..a198fbf --- /dev/null +++ b/src/Bios.c @@ -0,0 +1,94 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// Bios.c +// ---------------------------------------------------------------------------- +#include +#include +#include +#include + +#include "Bios.h" + +bool bios_enabled = false; +char bios_filename[256]; + +static uint8_t* bios_data = NULL; +static uint16_t bios_size = 0; + +bool bios_Load(const char *filename) { + bios_Release(); + //logger_LogInfo("Opening bios file " + filename + ".", BIOS_SOURCE); + + if (bios_size == 0) { + FILE* file = fopen(filename, "rb"); + if (file == NULL) { + //logger_LogError("Failed to open the bios file " + filename + " for reading.", BIOS_SOURCE); + return false; + } + + if (fseek(file, 0L, SEEK_END)) { + fclose(file); + //logger_LogError("Failed to find the end of the bios file.", BIOS_SOURCE); + return false; + } + + bios_size = ftell(file); + if (fseek(file, 0L, SEEK_SET)) { + fclose(file); + //logger_LogError("Failed to find the size of the bios file.", BIOS_SOURCE); + return false; + } + + bios_data = (uint8_t*)malloc(bios_size * sizeof(uint8_t)); + if (fread(bios_data, 1, bios_size, file) != bios_size && ferror(file)) { + fclose(file); + //logger_LogError("Failed to read the bios data.", BIOS_SOURCE); + bios_Release( ); + return false; + } + + fclose(file); + } + + snprintf(bios_filename, sizeof(bios_filename), "%s", filename); + return true; +} + +bool bios_IsLoaded(void) { + return (bios_data != NULL) ? true : false; +} + +void bios_Release(void) { + if (bios_data) { + free(bios_data); + bios_size = 0; + bios_data = NULL; + } +} + +void bios_Store(void) { + if (bios_data != NULL && bios_enabled) { + memory_WriteROM(65536 - bios_size, bios_size, bios_data); + } +} diff --git a/core/Bios.h b/src/Bios.h old mode 100755 new mode 100644 similarity index 68% rename from core/Bios.h rename to src/Bios.h index 6dd7954..fe89ee9 --- a/core/Bios.h +++ b/src/Bios.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -25,20 +26,13 @@ #ifndef BIOS_H #define BIOS_H -#include #include "Memory.h" -#include "Archive.h" -#include "Logger.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern bool bios_Load(std::string filename); -extern bool bios_IsLoaded( ); -extern void bios_Store( ); -extern void bios_Release( ); -extern std::string bios_filename; +extern bool bios_Load(const char *filename); +extern bool bios_IsLoaded(void); +extern void bios_Store(void); +extern void bios_Release(void); +extern char bios_filename[256]; extern bool bios_enabled; -#endif \ No newline at end of file +#endif diff --git a/src/Cartridge.c b/src/Cartridge.c new file mode 100644 index 0000000..580edc5 --- /dev/null +++ b/src/Cartridge.c @@ -0,0 +1,459 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// Cartridge.c +// ---------------------------------------------------------------------------- +#include +#include +#include +#include +#include + +#include "Cartridge.h" + +char cart_digest[33]; + +const char *cartridge_filename; +char cartridge_title[33]; +uint8_t cartridge_type; +uint8_t cartridge_region; +bool cartridge_pokey; +bool cartridge_pokey450; +uint8_t cartridge_controller[2]; +uint8_t cartridge_bank; +uint32_t cartridge_flags; +int cartridge_crosshair_x; +int cartridge_crosshair_y; +bool cartridge_dualanalog = false; +bool cartridge_xm = false; +bool cartridge_disable_bios = false; +uint8_t cartridge_left_switch = 1; +uint8_t cartridge_right_switch = 0; +bool cartridge_swap_buttons = false; +bool cartridge_hsc_enabled = false; +uint32_t cartridge_hblank = HBLANK_DEFAULT; + +static uint8_t *cartridge_buffer = NULL; +static size_t cartridge_size = 0; + +static bool cartridge_HasHeader(const uint8_t* header) { + const char HEADER_ID[ ] = {"ATARI7800"}; + + for (int index = 0; index < 9; index++) { + if (HEADER_ID[index] != header[index + 1]) { + return false; + } + } + return true; +} + +static bool cartridge_CC2(const uint8_t* header) { + const char HEADER_ID[ ] = {">>"}; + for (int index = 0; index < 2; index++) { + if (HEADER_ID[index] != header[index+1]) { + return false; + } + } + return true; +} + +static uint32_t cartridge_GetBank(uint8_t bank) { + if ((cartridge_type == CARTRIDGE_TYPE_SUPERCART || + cartridge_type == CARTRIDGE_TYPE_SUPERCART_ROM || + cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM) && + cartridge_size <= 65536) { + // for some of these carts, there are only 4 banks. in this case we + // ignore bit 3 previously, games of this type had to be doubled. The + // first 4 banks needed to be duplicated at the end of the ROM + return (bank & 3); + } + + return bank; +} + +static uint32_t cartridge_GetBankOffset(uint8_t bank) { + return cartridge_GetBank(bank) * 16384; +} + +static void cartridge_WriteBank(uint16_t address, uint8_t bank) { + uint32_t offset = cartridge_GetBankOffset(bank); + if (offset < cartridge_size) { + memory_WriteROM(address, 16384, cartridge_buffer + offset); + cartridge_bank = bank; + } +} + +static void cartridge_SetTypeBySize(uint32_t size) { + if (size <= 0x10000) { + cartridge_type = CARTRIDGE_TYPE_NORMAL; + } + else if (size == 0x24000) { + cartridge_type = CARTRIDGE_TYPE_SUPERCART_LARGE; + } + else if (size == 0x20000) { + cartridge_type = CARTRIDGE_TYPE_SUPERCART_ROM; + } + else { + cartridge_type = CARTRIDGE_TYPE_SUPERCART; + } +} + +static void cartridge_ReadHeader(const uint8_t* header) { + for (int index = 0; index < 32; index++) { + cartridge_title[index] = header[index + 17]; + } + + cartridge_size = header[49] << 24; + cartridge_size |= header[50] << 16; + cartridge_size |= header[51] << 8; + cartridge_size |= header[52]; + + if (header[53] == 0) { + if (cartridge_size > 131072) { + cartridge_type = CARTRIDGE_TYPE_SUPERCART_LARGE; + } + else if (header[54] == 2 || header[54] == 3) { + cartridge_type = CARTRIDGE_TYPE_SUPERCART; + } + else if (header[54] == 4 || header[54] == 5 || header[54] == 6 || + header[54] == 7) { + cartridge_type = CARTRIDGE_TYPE_SUPERCART_RAM; + } + else if (header[54] == 8 || header[54] == 9 || header[54] == 10 || + header[54] == 11) { + cartridge_type = CARTRIDGE_TYPE_SUPERCART_ROM; + } + else { + cartridge_type = CARTRIDGE_TYPE_NORMAL; + } + } + else { + if (header[53] == 2 /*1*/) { // Wii: Abs and Act were swapped + cartridge_type = CARTRIDGE_TYPE_ABSOLUTE; + } + else if (header[53] == 1 /*2*/) { // Wii: Abs and Act were swapped + cartridge_type = CARTRIDGE_TYPE_ACTIVISION; + } + else { + cartridge_type = CARTRIDGE_TYPE_NORMAL; + } + } + + cartridge_pokey = (header[54] & 1) ? true : false; + cartridge_pokey450 = (header[54] & 0x40)? true : false; + if (cartridge_pokey450) { + cartridge_pokey = true; + } + cartridge_controller[0] = header[55]; + cartridge_controller[1] = header[56]; + cartridge_region = header[57]; + cartridge_flags = 0; + cartridge_xm = (header[63] & 1) ? true: false; + cartridge_hsc_enabled = header[58] & 0x01; + + // Wii: Updates to header interpretation + uint8_t ct1 = header[54]; + if (header[53] == 0) { + // BIT1 and BIT3 (Supercart Large: 2) rom at $4000 + if ((ct1 & 0x0a) == 0x0a) { + cartridge_type = CARTRIDGE_TYPE_SUPERCART_LARGE; + } + // BIT1 and BIT4 (Supercart ROM: 4) bank6 at $4000 + else if ((ct1 & 0x12) == 0x12) { + cartridge_type = CARTRIDGE_TYPE_SUPERCART_ROM; + } + // BIT1 and BIT2 (Supercart RAM: 3) ram at $4000 + else if ((ct1 & 0x06) == 0x06) { + cartridge_type = CARTRIDGE_TYPE_SUPERCART_RAM; + } + // BIT1 (Supercart) bank switched + else if ((ct1 & 0x02) == 0x02) { + cartridge_type = CARTRIDGE_TYPE_SUPERCART; + } + // Size < 64k && BIT2 (Normal RAM: ?) ram at $4000 ) + else if (cartridge_size <= 0x10000 && ((ct1&0x04)==0x04)) { + cartridge_type = CARTRIDGE_TYPE_NORMAL_RAM; + } + // Attempt to determine the cartridge type based on its size + else { + cartridge_SetTypeBySize(cartridge_size); + } + } +} + +bool cartridge_Load(const uint8_t* data, uint32_t size) { + if (size <= 128) { + // Cartridge data is invalid. + return false; + } + + cartridge_Release( ); + + uint8_t header[128] = {0}; + + for(int index = 0; index < 128; index++) { + header[index] = data[index]; + } + + if (cartridge_CC2(header)) { + // Prosystem doesn't support CC2 hacks. + return false; + } + + uint32_t offset = 0; + + if (cartridge_HasHeader(header)) { + cartridge_ReadHeader(header); + size -= 128; + offset = 128; + + // Several cartridge headers do not have the proper size. So attempt to + // use the size of the file. + if (cartridge_size != size) { + // Necessary for the following roms: + // Impossible Mission hacks w/ C64 style graphics + if (size % 1024 == 0) { + cartridge_size = size; + } + } + } + else { + cartridge_size = size; + // Attempt to guess the cartridge type based on its size + cartridge_SetTypeBySize(size); + } + + cartridge_buffer = (uint8_t*)malloc(cartridge_size * sizeof(uint8_t)); + + for(size_t index = 0; index < cartridge_size; index++) { + cartridge_buffer[index] = data[index + offset]; + } + + // Different from the file md5sum which starts from the header vs rom data + MD5_CTX c; + size_t md5len = cartridge_size; + uint8_t *dataptr = cartridge_buffer; + unsigned char digest[16]; + MD5_Init(&c); + MD5_Update(&c, dataptr, md5len); + MD5_Final(digest, &c); + for (int i = 0; i < 16; i++) { + snprintf(&(cart_digest[i * 2]), 16 * 2, "%02x", (unsigned)digest[i]); + } + + return true; +} + +void cartridge_Store(void) { + switch(cartridge_type) { + case CARTRIDGE_TYPE_NORMAL: { + memory_WriteROM(65536 - cartridge_size, cartridge_size, cartridge_buffer); + break; + } + case CARTRIDGE_TYPE_NORMAL_RAM: { + memory_WriteROM(65536 - cartridge_size, cartridge_size, cartridge_buffer); + memory_ClearROM(16384, 16384); + break; + } + case CARTRIDGE_TYPE_SUPERCART: { + uint32_t offset = cartridge_size - 16384; + if (offset < cartridge_size) { + memory_WriteROM(49152, 16384, cartridge_buffer + offset); + } + break; + } + case CARTRIDGE_TYPE_SUPERCART_LARGE: { + uint32_t offset = cartridge_size - 16384; + if (offset < cartridge_size) { + memory_WriteROM(49152, 16384, cartridge_buffer + offset); + memory_WriteROM(16384, 16384, cartridge_buffer + cartridge_GetBankOffset(0)); + } + break; + } + case CARTRIDGE_TYPE_SUPERCART_RAM: { + uint32_t offset = cartridge_size - 16384; + if (offset < cartridge_size) { + memory_WriteROM(49152, 16384, cartridge_buffer + offset); + memory_ClearROM(16384, 16384); + } + break; + } + case CARTRIDGE_TYPE_SUPERCART_ROM: { + uint32_t offset = cartridge_size - 16384; + if (offset < cartridge_size && cartridge_GetBankOffset(6) < cartridge_size) { + memory_WriteROM(49152, 16384, cartridge_buffer + offset); + memory_WriteROM(16384, 16384, cartridge_buffer + cartridge_GetBankOffset(6)); + } + break; + } + case CARTRIDGE_TYPE_ABSOLUTE: { + memory_WriteROM(16384, 16384, cartridge_buffer); + memory_WriteROM(32768, 32768, cartridge_buffer + cartridge_GetBankOffset(2)); + break; + } + case CARTRIDGE_TYPE_ACTIVISION: { + if (122880 < cartridge_size) { + memory_WriteROM(40960, 16384, cartridge_buffer); + memory_WriteROM(16384, 8192, cartridge_buffer + 106496); + memory_WriteROM(24576, 8192, cartridge_buffer + 98304); + memory_WriteROM(32768, 8192, cartridge_buffer + 122880); + memory_WriteROM(57344, 8192, cartridge_buffer + 114688); + } + break; + } + } +} + +void cartridge_Write(uint16_t address, uint8_t data) { + switch(cartridge_type) { + case CARTRIDGE_TYPE_SUPERCART: + case CARTRIDGE_TYPE_SUPERCART_RAM: + case CARTRIDGE_TYPE_SUPERCART_ROM: + if (address >= 32768 && address < 49152 && data < 9) { + cartridge_StoreBank(data); + } + break; + + case CARTRIDGE_TYPE_SUPERCART_LARGE: + if (address >= 32768 && address < 49152 && data < 9) { + cartridge_StoreBank(data + 1); + } + break; + + case CARTRIDGE_TYPE_ABSOLUTE: + if (address == 32768 && (data == 1 || data == 2)) { + cartridge_StoreBank(data - 1); + } + break; + + case CARTRIDGE_TYPE_ACTIVISION: + if (address >= 65408) { + cartridge_StoreBank(address & 7); + } + break; + } +#if 0 // Wii: Moved to Memory.cpp + if (cartridge_pokey && address >= 0x4000 && address <= 0x400f) { + switch (address) { + case POKEY_AUDF1: + pokey_SetRegister(POKEY_AUDF1, data); + break; + + case POKEY_AUDC1: + pokey_SetRegister(POKEY_AUDC1, data); + break; + + case POKEY_AUDF2: + pokey_SetRegister(POKEY_AUDF2, data); + break; + + case POKEY_AUDC2: + pokey_SetRegister(POKEY_AUDC2, data); + break; + + case POKEY_AUDF3: + pokey_SetRegister(POKEY_AUDF3, data); + break; + + case POKEY_AUDC3: + pokey_SetRegister(POKEY_AUDC3, data); + break; + + case POKEY_AUDF4: + pokey_SetRegister(POKEY_AUDF4, data); + break; + + case POKEY_AUDC4: + pokey_SetRegister(POKEY_AUDC4, data); + break; + + case POKEY_AUDCTL: + pokey_SetRegister(POKEY_AUDCTL, data); + break; + + case POKEY_SKCTLS: + pokey_SetRegister(POKEY_SKCTLS, data); + break; + } + } +#endif +} + +void cartridge_StoreBank(uint8_t bank) { + switch (cartridge_type) { + case CARTRIDGE_TYPE_SUPERCART: + cartridge_WriteBank(32768, bank); + break; + + case CARTRIDGE_TYPE_SUPERCART_RAM: + cartridge_WriteBank(32768, bank); + break; + + case CARTRIDGE_TYPE_SUPERCART_ROM: + cartridge_WriteBank(32768, bank); + break; + + case CARTRIDGE_TYPE_SUPERCART_LARGE: + cartridge_WriteBank(32768, bank); + break; + + case CARTRIDGE_TYPE_ABSOLUTE: + cartridge_WriteBank(16384, bank); + break; + + case CARTRIDGE_TYPE_ACTIVISION: + cartridge_WriteBank(40960, bank); + break; + } +} + +bool cartridge_IsLoaded(void) { + return (cartridge_buffer != NULL) ? true : false; +} + +void cartridge_Release(void) { + if(cartridge_buffer != NULL) { + free(cartridge_buffer); + cartridge_size = 0; + cartridge_buffer = NULL; + cartridge_title[0] = '\0'; + cartridge_type = 0; + cartridge_region = 0; + cartridge_pokey = 0; + cartridge_pokey450 = 0; + cartridge_xm = false; + // Default to joysticks + memset(cartridge_controller, 1, sizeof(cartridge_controller)); + cartridge_bank = 0; + cartridge_flags = 0; + cartridge_disable_bios = false; + cartridge_crosshair_x = 0; + cartridge_crosshair_y = 0; + cartridge_hblank = HBLANK_DEFAULT; + cartridge_dualanalog = false; + cartridge_left_switch = 1; + cartridge_right_switch = 0; + cartridge_swap_buttons = false; + cartridge_hsc_enabled = false; + } +} diff --git a/core/Cartridge.h b/src/Cartridge.h old mode 100755 new mode 100644 similarity index 64% rename from core/Cartridge.h rename to src/Cartridge.h index 8b661ee..9d627c7 --- a/core/Cartridge.h +++ b/src/Cartridge.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -24,6 +25,7 @@ // ---------------------------------------------------------------------------- #ifndef CARTRIDGE_H #define CARTRIDGE_H + #define CARTRIDGE_TYPE_NORMAL 0 #define CARTRIDGE_TYPE_SUPERCART 1 #define CARTRIDGE_TYPE_SUPERCART_LARGE 2 @@ -40,53 +42,41 @@ #define HBLANK_DEFAULT 34 -#include -#include #include "Equates.h" #include "Memory.h" -#include "Hash.h" -#include "Logger.h" +#include "md5.h" #include "Pokey.h" -#include "Archive.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern bool cartridge_Load(std::string filename); -extern void cartridge_Store( ); -extern void cartridge_StoreBank(byte bank); -extern void cartridge_Write(word address, byte data); -extern bool cartridge_IsLoaded( ); -extern void cartridge_Release( ); -extern std::string cartridge_digest; -extern std::string cartridge_title; -extern std::string cartridge_description; -extern std::string cartridge_year; -extern std::string cartridge_maker; -extern std::string cartridge_filename; -extern byte cartridge_type; -extern byte cartridge_region; +extern bool cartridge_Load(const uint8_t* data, uint32_t size); +extern void cartridge_Store(void); +extern void cartridge_StoreBank(uint8_t bank); +extern void cartridge_Write(uint16_t address, uint8_t data); +extern bool cartridge_IsLoaded(void); +extern void cartridge_Release(void); +extern char cart_digest[33]; +extern const char *cartridge_filename; +extern char cartridge_title[33]; +extern uint8_t cartridge_type; +extern uint8_t cartridge_region; extern bool cartridge_pokey; extern bool cartridge_pokey450; extern bool cartridge_xm; -extern byte cartridge_controller[2]; -extern byte cartridge_bank; -extern uint cartridge_flags; +extern uint8_t cartridge_controller[2]; +extern uint8_t cartridge_bank; +extern uint32_t cartridge_flags; extern bool cartridge_disable_bios; -extern byte cartridge_left_switch; -extern byte cartridge_right_switch; +extern uint8_t cartridge_left_switch; +extern uint8_t cartridge_right_switch; extern bool cartridge_swap_buttons; +extern bool cartridge_hsc_enabled; // The x offset for the lightgun crosshair (allows per cartridge adjustments) extern int cartridge_crosshair_x; // The y offset for the lightgun crosshair (allows per cartridge adjustments) extern int cartridge_crosshair_y; // The hblank prior to DMA -extern uint cartridge_hblank; +extern uint32_t cartridge_hblank; // Whether the cartridge supports dual analog extern bool cartridge_dualanalog; -// Whether the high score cart is enabled -extern bool cartridge_hsc_enabled; #endif diff --git a/src/Database.c b/src/Database.c new file mode 100644 index 0000000..7cfd96f --- /dev/null +++ b/src/Database.c @@ -0,0 +1,124 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// Database.c +// ---------------------------------------------------------------------------- +#include +#include +#include +#include +#include + +#include "Database.h" + +bool cart_in_db = false; +bool database_enabled = true; +const char *database_filename; + +bool database_Load(const char *digest) { + cart_in_db = false; + + if (database_enabled) { + FILE* file = fopen(database_filename, "r"); + if (file == NULL) { + return false; + } + + // max count of items in the database + static int count = 17; + + char buffer[256]; + while (fgets(buffer, 256, file) != NULL) { + if (strstr(buffer, digest)) { + cart_in_db = true; + char entry[count][256]; + for (int index = 0; index < count; ++index) { + char *buf = fgets(buffer, 256, file); + buffer[strcspn(buf, "\r\n")] = 0; + snprintf(entry[index], sizeof(entry[index]), "%s", buffer); + } + + cartridge_type = (uint8_t)atoi(strchr(entry[1], '=') + 1); + + cartridge_pokey = (uint8_t)atoi(strchr(entry[2], '=') + 1); + + cartridge_controller[0] = (uint8_t)atoi(strchr(entry[3], '=') + 1); + cartridge_controller[1] = (uint8_t)atoi(strchr(entry[4], '=') + 1); + + cartridge_region = (uint8_t)atoi(strchr(entry[5], '=') + 1); + + cartridge_flags = (uint32_t)atoi(strchr(entry[6], '=') + 1); + + // Optionally load the lightgun crosshair offsets, hblank, dual analog + for (int index = 7; index < 11; ++index) { + if (strstr(entry[index], "crossx")) { + cartridge_crosshair_x = (int)atoi(strchr(entry[index], '=') + 1); + } + + if (strstr(entry[index], "crossy")) { + cartridge_crosshair_y = (int)atoi(strchr(entry[index], '=') + 1); + } + + if (strstr(entry[index], "hblank")) { + cartridge_hblank = (int)atoi(strchr(entry[index], '=') + 1); + } + + if (strstr(entry[index], "dualanalog")) { + cartridge_dualanalog = (uint8_t)atoi(strchr(entry[index], '=') + 1); + } + + if (strstr(entry[index], "pokey450")) { + cartridge_pokey450 = (uint8_t)atoi(strchr(entry[index], '=') + 1); + if (cartridge_pokey450) { + cartridge_pokey = 1; + } + } + + if (strstr(entry[index], "disablebios")) { + cartridge_disable_bios = (uint8_t)atoi(strchr(entry[index], '=') + 1); + } + + if (strstr(entry[index], "leftswitch")) { + cartridge_left_switch = (uint8_t)atoi(strchr(entry[index], '=') + 1); + } + + if (strstr(entry[index], "rightswitch")) { + cartridge_right_switch = (uint8_t)atoi(strchr(entry[index], '=') + 1); + } + + if (strstr(entry[index], "swapbuttons")) { + cartridge_swap_buttons = (uint8_t)atoi(strchr(entry[index], '=') + 1); + } + + if (strstr(entry[index], "hsc")) { + cartridge_hsc_enabled = (uint8_t)atoi(strchr(entry[index], '=') + 1); + } + } + + break; + } + } + fclose(file); + } + return true; +} diff --git a/core/Database.h b/src/Database.h old mode 100755 new mode 100644 similarity index 71% rename from core/Database.h rename to src/Database.h index 01e1c97..7cb5b86 --- a/core/Database.h +++ b/src/Database.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -25,19 +26,11 @@ #ifndef DATABASE_H #define DATABASE_H -#include #include "Cartridge.h" -#include "Logger.h" -#include "Common.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern void database_Initialize( ); -extern bool database_Load(std::string digest); -extern bool database_enabled; -extern std::string database_filename; +extern bool database_Load(const char *digest); extern bool cart_in_db; +extern bool database_enabled; +extern const char *database_filename; #endif diff --git a/core/Equates.h b/src/Equates.h old mode 100755 new mode 100644 similarity index 87% rename from core/Equates.h rename to src/Equates.h index 4e6c832..8265f1b --- a/core/Equates.h +++ b/src/Equates.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -71,7 +72,7 @@ #define P7C2 62 #define P7C3 63 #define SWCHA 640 -#define CTLSWA 641 +#define CTLSWA 641 #define SWCHB 642 #define CTLSWB 643 #define INTIM 644 diff --git a/core/ExpansionModule.cpp b/src/ExpansionModule.c similarity index 67% rename from core/ExpansionModule.cpp rename to src/ExpansionModule.c index 26f1e63..9f9331c 100644 --- a/core/ExpansionModule.cpp +++ b/src/ExpansionModule.c @@ -1,81 +1,84 @@ -/* - Memory map: - - POKEY1 $0450 $045F 16 bytes - POKEY2* $0460 $046F 16 bytes - XCTRL $0470 $047F 1 byte - RAM $4000 $7FFF 16384 bytes - -XCTRL Bit Description - -+-------------------------------+ -| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | -+-------------------------------+ - | | | | | | | | - | | | | | | | +-- Bank select bit 0 \ - | | | | | | +------ Bank select bit 1 | Totally 128 KByte in 16 KByte banks - | | | | | +---------- Bank select bit 3 / - | | | | +-------------- Enable memory bit (1 = Memory enabled, 0 after power on) - | | | +------------------ Enable POKEY bit** (1 = POKEY enabled, 0 after power on) - | | | - NA NA NA = Not Available or Not Used - -* = Can be mounted piggy back on the first POKEY. Description how to do this will come when i have tried it out. -** This bit controls both POKEY chip select signals. - - -The mapping is totally non compatible with pretty much everything. -There is a bank select latch located at $0470 and the POKEY is located at $0450 -(There's also a chip select output ($0460) on the PLD which alows you to simply piggy back a second POKEY). -Since the PLD is reconfigurable I could map the POKEY (or the RAM for that matter) to pretty much anything -if you wanted to. However since the PLD is soldered under the POKEY this needs to be configured before delivery. -*/ - -#include -#include "ExpansionModule.h" - -byte xm_ram[XM_RAM_SIZE] = {0}; -byte xm_reg = 0; -byte xm_bank = 0; -bool xm_pokey_enabled = false; -bool xm_mem_enabled = false; - -void xm_Reset() { - memset(xm_ram, 0, XM_RAM_SIZE); - xm_bank = 0; - xm_reg = 0; - xm_pokey_enabled = false; - xm_mem_enabled = false; -} - -byte xm_Read(word address) { - if (xm_pokey_enabled && (address >= 0x0450 && address < 0x0460)) { - byte b = pokey_GetRegister(0x4000 + (address - 0x0450)); - return b; - } else if (xm_pokey_enabled && (address >= 0x0460 && address < 0x0470)) { - byte b = pokey_GetRegister(0x4000 + (address - 0x0460)); - return b; - } else if (xm_mem_enabled && (address >= 0x4000 && address < 0x8000)) { - byte b = xm_ram[(xm_bank * 0x4000) + (address - 0x4000)]; - return b; - } else if (address >= 0x0470 && address < 0x0480) { - // TODO: Should the value be returned? - } - return 0; -} - -void xm_Write(word address, byte data) { - if (xm_pokey_enabled && (address >= 0x0450 && address < 0x0460)) { - pokey_SetRegister(0x4000 + (address - 0x0450), data); - } else if (xm_pokey_enabled && (address >= 0x0460 && address < 0x0470)) { - pokey_SetRegister(0x4000 + (address - 0x0460), data); - } else if (xm_mem_enabled && (address >= 0x4000 && address < 0x8000)) { - - xm_ram[(xm_bank * 0x4000) + (address - 0x4000)] = data; - } else if (address >= 0x0470 && address < 0x0480) { - xm_reg = data; - xm_bank = xm_reg & 7; - xm_pokey_enabled = (xm_reg & 0x10) > 0; - xm_mem_enabled = (xm_reg & 0x08) > 0; - } -} +/* + Memory map: + POKEY1 $0450 $045F 16 bytes + POKEY2* $0460 $046F 16 bytes + XCTRL $0470 $047F 1 byte + RAM $4000 $7FFF 16384 bytes +XCTRL Bit Description ++-------------------------------+ +| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ++-------------------------------+ + | | | | | | | | + | | | | | | | +-- Bank select bit 0 \ + | | | | | | +------ Bank select bit 1 | Totally 128 KByte in 16 KByte banks + | | | | | +---------- Bank select bit 3 / + | | | | +-------------- Enable memory bit (1 = Memory enabled, 0 after power on) + | | | +------------------ Enable POKEY bit** (1 = POKEY enabled, 0 after power on) + | | | + NA NA NA = Not Available or Not Used +* = Can be mounted piggy back on the first POKEY. Description how to do this will come when i have tried it out. +** This bit controls both POKEY chip select signals. +The mapping is totally non compatible with pretty much everything. +There is a bank select latch located at $0470 and the POKEY is located at $0450 +(There's also a chip select output ($0460) on the PLD which alows you to simply piggy back a second POKEY). +Since the PLD is reconfigurable I could map the POKEY (or the RAM for that matter) to pretty much anything +if you wanted to. However since the PLD is soldered under the POKEY this needs to be configured before delivery. +*/ + +#include +#include + +#include "ExpansionModule.h" + +uint8_t xm_ram[XM_RAM_SIZE] = {0}; +uint8_t xm_reg = 0; +uint8_t xm_bank = 0; +bool xm_pokey_enabled = false; +bool xm_mem_enabled = false; + +void xm_Reset(void) { + for (int i = 0; i < XM_RAM_SIZE; i++) { + xm_ram[i] = 0; + } + xm_bank = 0; + xm_reg = 0; + xm_pokey_enabled = false; + xm_mem_enabled = false; +} + +uint8_t xm_Read(uint16_t address) { + if (xm_pokey_enabled && (address >= 0x0450 && address < 0x0460)) { + uint8_t b = pokey_GetRegister(0x4000 + (address - 0x0450)); + return b; + } + else if (xm_pokey_enabled && (address >= 0x0460 && address < 0x0470)) { + uint8_t b = pokey_GetRegister(0x4000 + (address - 0x0460)); + return b; + } + else if (xm_mem_enabled && (address >= 0x4000 && address < 0x8000)) { + uint8_t b = xm_ram[(xm_bank * 0x4000) + (address - 0x4000)]; + return b; + } + else if (address >= 0x0470 && address < 0x0480) { + // TODO: Should the value be returned? + } + return 0; +} + +void xm_Write(uint16_t address, uint8_t data) { + if (xm_pokey_enabled && (address >= 0x0450 && address < 0x0460)) { + pokey_SetRegister(0x4000 + (address - 0x0450), data); + } + else if (xm_pokey_enabled && (address >= 0x0460 && address < 0x0470)) { + pokey_SetRegister(0x4000 + (address - 0x0460), data); + } + else if (xm_mem_enabled && (address >= 0x4000 && address < 0x8000)) { + xm_ram[(xm_bank * 0x4000) + (address - 0x4000)] = data; + } + else if (address >= 0x0470 && address < 0x0480) { + xm_reg = data; + xm_bank = xm_reg & 7; + xm_pokey_enabled = (xm_reg & 0x10) > 0; + xm_mem_enabled = (xm_reg & 0x08) > 0; + } +} diff --git a/core/ExpansionModule.h b/src/ExpansionModule.h similarity index 50% rename from core/ExpansionModule.h rename to src/ExpansionModule.h index ee811b0..43a9fb5 100644 --- a/core/ExpansionModule.h +++ b/src/ExpansionModule.h @@ -1,19 +1,18 @@ -#ifndef EXPANSIONMODULE_H -#define EXPANSIONMODULE_H - -#include "Cartridge.h" -#include "Memory.h" - -#define XM_RAM_SIZE 0x20000 - -extern byte xm_ram[XM_RAM_SIZE]; -extern bool xm_pokey_enabled; -extern bool xm_mem_enabled; -extern byte xm_reg; -extern byte xm_bank; - - -void xm_Reset(); -byte xm_Read(word address); -void xm_Write(word address, byte data); -#endif +#ifndef EXPANSIONMODULE_H +#define EXPANSIONMODULE_H + +#include "Cartridge.h" +#include "Memory.h" + +#define XM_RAM_SIZE 0x20000 + +extern uint8_t xm_ram[XM_RAM_SIZE]; +extern bool xm_pokey_enabled; +extern bool xm_mem_enabled; +extern uint8_t xm_reg; +extern uint8_t xm_bank; + +void xm_Reset(void); +uint8_t xm_Read(uint16_t address); +void xm_Write(uint16_t address, uint8_t data); +#endif diff --git a/src/Maria.c b/src/Maria.c new file mode 100644 index 0000000..4d87a52 --- /dev/null +++ b/src/Maria.c @@ -0,0 +1,326 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// Maria.c +// ---------------------------------------------------------------------------- +#include +#include + +#include "Maria.h" +#define MARIA_LINERAM_SIZE 160 + +rect maria_displayArea = {0, 16, 319, 258}; +rect maria_visibleArea = {0, 26, 319, 248}; +uint8_t maria_surface[MARIA_SURFACE_SIZE] = {0}; +uint16_t maria_scanline = 1; + +static uint8_t maria_lineRAM[MARIA_LINERAM_SIZE]; +static uint32_t maria_cycles; +static pair maria_dpp; +static pair maria_dp; +static pair maria_pp; +static uint8_t maria_horizontal; +static uint8_t maria_palette; +static signed char maria_offset; +static uint8_t maria_h08; +static uint8_t maria_h16; +static uint8_t maria_wmode; + +static inline void maria_StoreCell(uint8_t data) { + if (maria_horizontal < MARIA_LINERAM_SIZE) { + if (data) { + maria_lineRAM[maria_horizontal] = maria_palette | data; + } + else { + uint8_t kmode = memory_ram[CTRL] & 4; + if (kmode) { + maria_lineRAM[maria_horizontal] = 0; + } + } + } + maria_horizontal++; +} + +static inline void maria_StoreCell2(uint8_t high, uint8_t low) { + if (maria_horizontal < MARIA_LINERAM_SIZE) { + if (low || high) { + maria_lineRAM[maria_horizontal] = (maria_palette & 16) | high | low; + } + else { + uint8_t kmode = memory_ram[CTRL] & 4; + if (kmode) { + maria_lineRAM[maria_horizontal] = 0; + } + } + } + maria_horizontal++; +} + +static inline bool maria_IsHolyDMA(void) { + if (maria_pp.w > 32767) { + if (maria_h16 && (maria_pp.w & 4096)) { + return true; + } + if (maria_h08 && (maria_pp.w & 2048)) { + return true; + } + } + return false; +} + +static inline uint8_t maria_GetColor(uint8_t data) { + if (data & 3) { + return memory_ram[BACKGRND + data]; + } + else { + return memory_ram[BACKGRND]; + } +} + +static inline void maria_StoreGraphic(void) { + uint8_t data = memory_ram[maria_pp.w]; + if (maria_wmode) { + if (maria_IsHolyDMA()) { + maria_StoreCell2(0, 0); + maria_StoreCell2(0, 0); + } + else { + maria_StoreCell2((data & 12), (data & 192) >> 6); + maria_StoreCell2((data & 48) >> 4, (data & 3) << 2); + } + } + else { + if(maria_IsHolyDMA()) { + maria_StoreCell(0); + maria_StoreCell(0); + maria_StoreCell(0); + maria_StoreCell(0); + } + else { + maria_StoreCell((data & 192) >> 6); + maria_StoreCell((data & 48) >> 4); + maria_StoreCell((data & 12) >> 2); + maria_StoreCell(data & 3); + } + } + maria_pp.w++; +} + +static inline void maria_WriteLineRAM(uint8_t* buffer) { + uint8_t rmode = memory_ram[CTRL] & 3; + if (rmode == 0) { // 160A/B + int pixel = 0; + for (int index = 0; index < MARIA_LINERAM_SIZE; index += 4) { + uint16_t color; + color = maria_GetColor(maria_lineRAM[index + 0]); + buffer[pixel++] = color; + buffer[pixel++] = color; + color = maria_GetColor(maria_lineRAM[index + 1]); + buffer[pixel++] = color; + buffer[pixel++] = color; + color = maria_GetColor(maria_lineRAM[index + 2]); + buffer[pixel++] = color; + buffer[pixel++] = color; + color = maria_GetColor(maria_lineRAM[index + 3]); + buffer[pixel++] = color; + buffer[pixel++] = color; + } + } + else if (rmode == 2) { // 320B/D + int pixel = 0; + for (int index = 0; index < MARIA_LINERAM_SIZE; index += 4) { + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 0] & 16) | ((maria_lineRAM[index + 0] & 8) >> 3) | ((maria_lineRAM[index + 0] & 2))); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 0] & 16) | ((maria_lineRAM[index + 0] & 4) >> 2) | ((maria_lineRAM[index + 0] & 1) << 1)); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 1] & 16) | ((maria_lineRAM[index + 1] & 8) >> 3) | ((maria_lineRAM[index + 1] & 2))); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 1] & 16) | ((maria_lineRAM[index + 1] & 4) >> 2) | ((maria_lineRAM[index + 1] & 1) << 1)); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 2] & 16) | ((maria_lineRAM[index + 2] & 8) >> 3) | ((maria_lineRAM[index + 2] & 2))); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 2] & 16) | ((maria_lineRAM[index + 2] & 4) >> 2) | ((maria_lineRAM[index + 2] & 1) << 1)); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 3] & 16) | ((maria_lineRAM[index + 3] & 8) >> 3) | ((maria_lineRAM[index + 3] & 2))); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 3] & 16) | ((maria_lineRAM[index + 3] & 4) >> 2) | ((maria_lineRAM[index + 3] & 1) << 1)); + } + } + else if (rmode == 3) { // 320A/C + int pixel = 0; + for (int index = 0; index < MARIA_LINERAM_SIZE; index += 4) { + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 0] & 30)); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 0] & 28) | ((maria_lineRAM[index + 0] & 1) << 1)); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 1] & 30)); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 1] & 28) | ((maria_lineRAM[index + 1] & 1) << 1)); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 2] & 30)); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 2] & 28) | ((maria_lineRAM[index + 2] & 1) << 1)); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 3] & 30)); + buffer[pixel++] = maria_GetColor((maria_lineRAM[index + 3] & 28) | ((maria_lineRAM[index + 3] & 1) << 1)); + } + } +} + +static inline void maria_StoreLineRAM(void) { + for(int index = 0; index < MARIA_LINERAM_SIZE; index++) { + maria_lineRAM[index] = 0; + } + + uint8_t mode = memory_ram[maria_dp.w + 1]; + while(mode & 0x5f) { + uint8_t width; + uint8_t indirect = 0; + + maria_pp.b.l = memory_ram[maria_dp.w]; + maria_pp.b.h = memory_ram[maria_dp.w + 2]; + + if (mode & 31) { + maria_cycles += 8; // Maria cycles (Header 4 uint8_t) + maria_palette = (memory_ram[maria_dp.w + 1] & 224) >> 3; + maria_horizontal = memory_ram[maria_dp.w + 3]; + width = memory_ram[maria_dp.w + 1] & 31; + width = ((~width) & 31) + 1; + maria_dp.w += 4; + } + else { + maria_cycles += 12; // Maria cycles (Header 5 uint8_t) + maria_palette = (memory_ram[maria_dp.w + 3] & 224) >> 3; + maria_horizontal = memory_ram[maria_dp.w + 4]; + indirect = memory_ram[maria_dp.w + 1] & 32; + maria_wmode = memory_ram[maria_dp.w + 1] & 128; + width = memory_ram[maria_dp.w + 3] & 31; + width = (width == 0)? 32: ((~width) & 31) + 1; + maria_dp.w += 5; + } + + if (!indirect) { + maria_pp.b.h += maria_offset; + for (int index = 0; index < width; index++) { + maria_cycles += 3; // Maria cycles (Direct graphic read) + maria_StoreGraphic( ); + } + } + else { + uint8_t cwidth = memory_ram[CTRL] & 16; + pair basePP = maria_pp; + for (int index = 0; index < width; index++) { + maria_cycles += 3; // Maria cycles (Indirect) + maria_pp.b.l = memory_ram[basePP.w++]; + maria_pp.b.h = memory_ram[CHARBASE] + maria_offset; + + maria_cycles += 3; // Maria cycles (Indirect, 1 uint8_t) + maria_StoreGraphic( ); + + if (cwidth) { + maria_cycles += 3; // Maria cycles (Indirect, 2 uint8_ts) + maria_StoreGraphic( ); + } + } + } + mode = memory_ram[maria_dp.w + 1]; + } +} + +void maria_Reset(void) { + maria_scanline = 1; + + for(int index = 0; index < MARIA_SURFACE_SIZE; index++) { + maria_surface[index] = 0; + } + + maria_cycles = 0; + maria_dpp.w = 0; + maria_dp.w = 0; + maria_pp.w = 0; + maria_horizontal = 0; + maria_palette = 0; + maria_offset = 0; + maria_h08 = 0; + maria_h16 = 0; + maria_wmode = 0; +} + +uint32_t maria_RenderScanline(void) { + maria_cycles = 0; + + // lightgun flash + // Displays the background color when Maria is disabled (if applicable) + if (((memory_ram[CTRL] & 96 ) != 64 ) && + maria_scanline >= maria_visibleArea.top && + maria_scanline <= maria_visibleArea.bottom) { + uint8_t bgcolor = maria_GetColor(0); + uint8_t *bgstart = maria_surface + ((maria_scanline - maria_displayArea.top) * + ((maria_displayArea.right - maria_displayArea.left) + 1)); + + for(uint32_t index = 0; index < MARIA_LINERAM_SIZE; index++ ) { + *bgstart++ = bgcolor; + *bgstart++ = bgcolor; + } + } + + if ((memory_ram[CTRL] & 96) == 64 && maria_scanline >= maria_displayArea.top && maria_scanline <= maria_displayArea.bottom) { + maria_cycles += 5; // Maria cycles (DMA Startup) + + if (maria_scanline == maria_displayArea.top) { + maria_cycles += 10; // Maria cycles (End of VBLANK) + maria_dpp.b.l = memory_ram[DPPL]; + maria_dpp.b.h = memory_ram[DPPH]; + maria_h08 = memory_ram[maria_dpp.w] & 32; + maria_h16 = memory_ram[maria_dpp.w] & 64; + maria_offset = memory_ram[maria_dpp.w] & 15; + maria_dp.b.l = memory_ram[maria_dpp.w + 2]; + maria_dp.b.h = memory_ram[maria_dpp.w + 1]; + + if (memory_ram[maria_dpp.w] & 128) { + maria_cycles += 20; // Maria cycles (NMI) /*29, 16, 20*/ + sally_ExecuteNMI( ); + } + } + else if (maria_scanline >= maria_visibleArea.top && maria_scanline <= maria_visibleArea.bottom) { + maria_WriteLineRAM(maria_surface + ((maria_scanline - maria_displayArea.top) * + ((maria_displayArea.right - maria_displayArea.left) + 1))); + } + + if (maria_scanline != maria_displayArea.bottom) { + maria_dp.b.l = memory_ram[maria_dpp.w + 2]; + maria_dp.b.h = memory_ram[maria_dpp.w + 1]; + maria_StoreLineRAM( ); + maria_offset--; + + if (maria_offset < 0) { + maria_cycles += 10; // Maria cycles (Last line of zone) /*20*/ + maria_dpp.w += 3; + maria_h08 = memory_ram[maria_dpp.w] & 32; + maria_h16 = memory_ram[maria_dpp.w] & 64; + maria_offset = memory_ram[maria_dpp.w] & 15; + if(memory_ram[maria_dpp.w] & 128) { + maria_cycles += 20; // Maria cycles (NMI) /*29, 16, 20*/ + sally_ExecuteNMI( ); + } + } + else { + maria_cycles += 4; // Maria cycles (Other lines of zone) + } + } + } + return maria_cycles; +} + +void maria_Clear(void) { + for(int index = 0; index < MARIA_SURFACE_SIZE; index++) { + maria_surface[index] = 0; + } +} diff --git a/core/Maria.h b/src/Maria.h old mode 100755 new mode 100644 similarity index 73% rename from core/Maria.h rename to src/Maria.h index 815a256..ca43218 --- a/core/Maria.h +++ b/src/Maria.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -24,6 +25,7 @@ // ---------------------------------------------------------------------------- #ifndef MARIA_H #define MARIA_H + #define MARIA_SURFACE_SIZE 93440 #include "Equates.h" @@ -32,16 +34,12 @@ #include "Rect.h" #include "Sally.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern void maria_Reset( ); -extern uint maria_RenderScanline( ); -extern void maria_Clear( ); +extern void maria_Reset(void); +extern uint32_t maria_RenderScanline(void); +extern void maria_Clear(void); extern rect maria_displayArea; extern rect maria_visibleArea; -extern byte maria_surface[MARIA_SURFACE_SIZE]; -extern word maria_scanline; +extern uint8_t maria_surface[MARIA_SURFACE_SIZE]; +extern uint16_t maria_scanline; -#endif \ No newline at end of file +#endif diff --git a/src/Memory.c b/src/Memory.c new file mode 100644 index 0000000..d3053fb --- /dev/null +++ b/src/Memory.c @@ -0,0 +1,226 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// Memory.cpp +// ---------------------------------------------------------------------------- +#include +#include +#include + +#include "Memory.h" +#include "ExpansionModule.h" + +uint8_t memory_ram[MEMORY_SIZE] = {0}; +uint8_t memory_rom[MEMORY_SIZE] = {0}; + +void memory_Reset(void) { + uint32_t index; + + for (index = 0; index < MEMORY_SIZE; index++) { + memory_ram[index] = 0; + memory_rom[index] = 1; + } + + for (index = 0; index < 16384; index++) { + memory_rom[index] = 0; + } +} + +uint8_t memory_Read(uint16_t address) { + uint8_t tmp_uint8_t; + + /*if (cartridge_pokey && address == POKEY_RANDOM) { + return pokey_GetRegister(POKEY_RANDOM); + }*/ + if (cartridge_xm) { + if ((address >= 0x0470 && address < 0x0480) || + (xm_pokey_enabled && (address >= 0x0450 && address < 0x0470)) || + (xm_mem_enabled && (address >= 0x4000 && address < 0x8000))) { + return xm_Read(address); + } + } + + if (cartridge_pokey && + ((!cartridge_pokey450 && (address >= 0x4000 && address <= 0x400f)) || + (cartridge_pokey450 && (address >= 0x0450 && address < 0x0470)))) { + return pokey_GetRegister( + cartridge_pokey450 ? 0x4000 + (address - 0x0450) : address + ); + } + + switch (address) { + case INTIM: + case INTIM | 0x2: + memory_ram[INTFLG] &= 0x7f; + return memory_ram[INTIM]; + + case INTFLG: + case INTFLG | 0x2: + tmp_uint8_t = memory_ram[INTFLG]; + memory_ram[INTFLG] &= 0x7f; + return tmp_uint8_t; + + default: + return memory_ram[address]; + } +} + +void memory_Write(uint16_t address, uint8_t data) { + if (cartridge_xm && + ((address >= 0x0470 && address < 0x0480) || + ((xm_pokey_enabled && (address >= 0x0450 && address < 0x0470)) || + (xm_mem_enabled && (address >= 0x4000 && address < 0x8000))))) { + xm_Write(address, data); + return; + } + + if (cartridge_pokey && + ((!cartridge_pokey450 && (address >= 0x4000 && address <= 0x400f)) || + (cartridge_pokey450 && (address >= 0x0450 && address < 0x0470)))) { + pokey_SetRegister( + (cartridge_pokey450 ? 0x4000 + (address - 0x0450) : address), data + ); + return; + } + + if (!memory_rom[address]) { + switch(address) { + case WSYNC: + if (!(cartridge_flags & 128)) { + memory_ram[WSYNC] = true; + } + break; + + case INPTCTRL: + if (data == 22 && cartridge_IsLoaded()) { + cartridge_Store(); + } + else if (data == 2 && bios_enabled) { + bios_Store(); + } + break; + + case INPT0: + case INPT1: + case INPT2: + case INPT3: + case INPT4: + case INPT5: + break; + + case AUDC0: + tia_SetRegister(AUDC0, data); + break; + + case AUDC1: + tia_SetRegister(AUDC1, data); + break; + + case AUDF0: + tia_SetRegister(AUDF0, data); + break; + + case AUDF1: + tia_SetRegister(AUDF1, data); + break; + + case AUDV0: + tia_SetRegister(AUDV0, data); + break; + + case AUDV1: + tia_SetRegister(AUDV1, data); + break; + + /*gdement: Writing here actually writes to DRA inside the RIOT chip. + This value only indirectly affects output of SWCHA. Ditto for SWCHB.*/ + case SWCHA: + riot_SetDRA(data); + break; + + case SWCHB: + riot_SetDRB(data); + break; + + case TIM1T: + case TIM1T | 0x8: + riot_SetTimer(TIM1T, data); + break; + + case TIM8T: + case TIM8T | 0x8: + riot_SetTimer(TIM8T, data); + break; + + case TIM64T: + case TIM64T | 0x8: + riot_SetTimer(TIM64T, data); + break; + + case T1024T: + case T1024T | 0x8: + riot_SetTimer(T1024T, data); + break; + + default: + memory_ram[address] = data; + + if (address >= 8256 && address <= 8447) { + memory_ram[address - 8192] = data; + } + else if (address >= 8512 && address <= 8702) { + memory_ram[address - 8192] = data; + } + else if (address >= 64 && address <= 255) { + memory_ram[address + 8192] = data; + } + else if (address >= 320 && address <= 511) { + memory_ram[address + 8192] = data; + } + break; + } + /*TODO: gdement: test here for debug port. Don't put it in the switch + because that will change behavior.*/ + } + else { + cartridge_Write(address, data); + } +} + +void memory_WriteROM(uint16_t address, uint32_t size, const uint8_t* data) { + if ((address + size) <= MEMORY_SIZE && data != NULL) { + for (uint32_t index = 0; index < size; index++) { + memory_ram[address + index] = data[index]; + memory_rom[address + index] = 1; + } + } +} + +void memory_ClearROM(uint16_t address, uint32_t size) { + if ((address + size) <= MEMORY_SIZE) { + for (uint32_t index = 0; index < size; index++) { + memory_ram[address + index] = 0; + memory_rom[address + index] = 0; + } + } +} diff --git a/core/Memory.h b/src/Memory.h old mode 100755 new mode 100644 similarity index 66% rename from core/Memory.h rename to src/Memory.h index 4b5d85e..d781b9b --- a/core/Memory.h +++ b/src/Memory.h @@ -1,10 +1,11 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael // // 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 @@ -24,7 +25,6 @@ // ---------------------------------------------------------------------------- #ifndef MEMORY_H #define MEMORY_H -#define MEMORY_SIZE 65536 #include "Equates.h" #include "Bios.h" @@ -32,16 +32,14 @@ #include "Tia.h" #include "Riot.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; +#define MEMORY_SIZE 65536 -extern void memory_Reset( ); -extern byte memory_Read(word address); -extern void memory_Write(word address, byte data); -extern void memory_WriteROM(word address, uint size, const byte* data); -extern void memory_ClearROM(word address, uint size); -extern byte memory_ram[MEMORY_SIZE]; -extern byte memory_rom[MEMORY_SIZE]; +extern void memory_Reset(void); +extern uint8_t memory_Read(uint16_t address); +extern void memory_Write(uint16_t address, uint8_t data); +extern void memory_WriteROM(uint16_t address, uint32_t size, const uint8_t* data); +extern void memory_ClearROM(uint16_t address, uint32_t size); +extern uint8_t memory_ram[MEMORY_SIZE]; +extern uint8_t memory_rom[MEMORY_SIZE]; #endif diff --git a/core/Pair.h b/src/Pair.h old mode 100755 new mode 100644 similarity index 73% rename from core/Pair.h rename to src/Pair.h index 16279ea..53be10a --- a/core/Pair.h +++ b/src/Pair.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -25,17 +26,14 @@ #ifndef PAIR_H #define PAIR_H -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; +typedef struct Join { + uint8_t l; + uint8_t h; +} Join; -union Pair { - word w; - struct Join { - byte l; - byte h; - } b; -}; +typedef union Pair { + uint16_t w; + Join b; +} pair; -typedef Pair pair; #endif diff --git a/src/Palette.c b/src/Palette.c new file mode 100644 index 0000000..89fa2c1 --- /dev/null +++ b/src/Palette.c @@ -0,0 +1,103 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// Palette.c +// ---------------------------------------------------------------------------- +#include +#include + +#include "Palette.h" + +bool palette_default = true; +uint8_t palette_data[PALETTE_SIZE] = { + 0x00,0x00,0x00,0x25,0x25,0x25,0x34,0x34,0x34,0x4F,0x4F,0x4F, + 0x5B,0x5B,0x5B,0x69,0x69,0x69,0x7B,0x7B,0x7B,0x8A,0x8A,0x8A, + 0xA7,0xA7,0xA7,0xB9,0xB9,0xB9,0xC5,0xC5,0xC5,0xD0,0xD0,0xD0, + 0xD7,0xD7,0xD7,0xE1,0xE1,0xE1,0xF4,0xF4,0xF4,0xFF,0xFF,0xFF, + 0x4C,0x32,0x00,0x62,0x3A,0x00,0x7B,0x4A,0x00,0x9A,0x60,0x00, + 0xB5,0x74,0x00,0xCC,0x85,0x00,0xE7,0x9E,0x08,0xF7,0xAF,0x10, + 0xFF,0xC3,0x18,0xFF,0xD0,0x20,0xFF,0xD8,0x28,0xFF,0xDF,0x30, + 0xFF,0xE6,0x3B,0xFF,0xF4,0x40,0xFF,0xFA,0x4B,0xFF,0xFF,0x50, + 0x99,0x25,0x00,0xAA,0x25,0x00,0xB4,0x25,0x00,0xD3,0x30,0x00, + 0xDD,0x48,0x02,0xE2,0x50,0x09,0xF4,0x67,0x00,0xF4,0x75,0x10, + 0xFF,0x9E,0x10,0xFF,0xAC,0x20,0xFF,0xBA,0x3A,0xFF,0xBF,0x50, + 0xFF,0xC6,0x6D,0xFF,0xD5,0x80,0xFF,0xE4,0x90,0xFF,0xE6,0x99, + 0x98,0x0C,0x0C,0x99,0x0C,0x0C,0xC2,0x13,0x00,0xD3,0x13,0x00, + 0xE2,0x35,0x00,0xE3,0x40,0x00,0xE4,0x40,0x20,0xE5,0x52,0x30, + 0xFD,0x78,0x54,0xFF,0x8A,0x6A,0xFF,0x98,0x7C,0xFF,0xA4,0x8B, + 0xFF,0xB3,0x9E,0xFF,0xC2,0xB2,0xFF,0xD0,0xBA,0xFF,0xD7,0xC0, + 0x99,0x00,0x00,0xA9,0x00,0x00,0xC2,0x04,0x00,0xD3,0x04,0x00, + 0xDA,0x04,0x00,0xDB,0x08,0x00,0xE4,0x20,0x20,0xF6,0x40,0x40, + 0xFB,0x70,0x70,0xFB,0x7E,0x7E,0xFB,0x8F,0x8F,0xFF,0x9F,0x9F, + 0xFF,0xAB,0xAB,0xFF,0xB9,0xB9,0xFF,0xC9,0xC9,0xFF,0xCF,0xCF, + 0x7E,0x00,0x50,0x80,0x00,0x50,0x80,0x00,0x5F,0x95,0x0B,0x74, + 0xAA,0x22,0x88,0xBB,0x2F,0x9A,0xCE,0x3F,0xAD,0xD7,0x5A,0xB6, + 0xE4,0x67,0xC3,0xEF,0x72,0xCE,0xFB,0x7E,0xDA,0xFF,0x8D,0xE1, + 0xFF,0x9D,0xE5,0xFF,0xA5,0xE7,0xFF,0xAF,0xEA,0xFF,0xB8,0xEC, + 0x48,0x00,0x6C,0x5C,0x04,0x88,0x65,0x0D,0x90,0x7B,0x23,0xA7, + 0x93,0x3B,0xBF,0x9D,0x45,0xC9,0xA7,0x4F,0xD3,0xB2,0x5A,0xDE, + 0xBD,0x65,0xE9,0xC5,0x6D,0xF1,0xCE,0x76,0xFA,0xD5,0x83,0xFF, + 0xDA,0x90,0xFF,0xDE,0x9C,0xFF,0xE2,0xA9,0xFF,0xE6,0xB6,0xFF, + 0x1B,0x00,0x70,0x22,0x1B,0x8D,0x37,0x30,0xA2,0x48,0x41,0xB3, + 0x59,0x52,0xC4,0x63,0x5C,0xCE,0x6F,0x68,0xDA,0x7D,0x76,0xE8, + 0x87,0x80,0xF8,0x93,0x8C,0xFF,0x9D,0x97,0xFF,0xA8,0xA3,0xFF, + 0xB3,0xAF,0xFF,0xBC,0xB8,0xFF,0xC4,0xC1,0xFF,0xDA,0xD1,0xFF, + 0x00,0x0D,0x7F,0x00,0x12,0xA7,0x00,0x18,0xC0,0x0A,0x2B,0xD1, + 0x1B,0x4A,0xE3,0x2F,0x58,0xF0,0x37,0x68,0xFF,0x49,0x79,0xFF, + 0x5B,0x85,0xFF,0x6D,0x96,0xFF,0x7F,0xA3,0xFF,0x8C,0xAD,0xFF, + 0x96,0xB4,0xFF,0xA8,0xC0,0xFF,0xB7,0xCB,0xFF,0xC6,0xD6,0xFF, + 0x00,0x29,0x5A,0x00,0x38,0x76,0x00,0x48,0x92,0x00,0x5C,0xAC, + 0x00,0x71,0xC6,0x00,0x86,0xD0,0x0A,0x9B,0xDF,0x1A,0xA8,0xEC, + 0x2B,0xB6,0xFF,0x3F,0xC2,0xFF,0x45,0xCB,0xFF,0x59,0xD3,0xFF, + 0x7F,0xDA,0xFF,0x8F,0xDE,0xFF,0xA0,0xE2,0xFF,0xB0,0xEB,0xFF, + 0x00,0x38,0x39,0x00,0x3C,0x48,0x00,0x3D,0x5B,0x02,0x66,0x7F, + 0x03,0x73,0x83,0x00,0x9C,0xAA,0x00,0xA1,0xBB,0x01,0xA4,0xCC, + 0x03,0xBB,0xFF,0x05,0xDA,0xE2,0x18,0xE5,0xFF,0x34,0xEA,0xFF, + 0x49,0xEF,0xFF,0x66,0xF2,0xFF,0x84,0xF4,0xFF,0x9E,0xF9,0xFF, + 0x00,0x4A,0x00,0x00,0x5D,0x00,0x00,0x70,0x00,0x00,0x8B,0x00, + 0x00,0xA9,0x00,0x00,0xBB,0x05,0x00,0xBD,0x00,0x02,0xD0,0x05, + 0x1A,0xD5,0x40,0x5A,0xF1,0x77,0x82,0xEF,0xA7,0x84,0xED,0xD1, + 0x89,0xFF,0xED,0x7D,0xFF,0xFF,0x93,0xFF,0xFF,0x9B,0xFF,0xFF, + 0x22,0x4A,0x03,0x27,0x53,0x04,0x30,0x64,0x05,0x3C,0x77,0x0C, + 0x45,0x8C,0x11,0x5A,0xA5,0x13,0x1B,0xD2,0x09,0x1F,0xDD,0x00, + 0x3D,0xCD,0x2D,0x3D,0xCD,0x30,0x58,0xCC,0x40,0x60,0xD3,0x50, + 0xA2,0xEC,0x55,0xB3,0xF2,0x4A,0xBB,0xF6,0x5D,0xC4,0xF8,0x70, + 0x2E,0x3F,0x0C,0x36,0x4A,0x0F,0x40,0x56,0x15,0x46,0x5F,0x17, + 0x57,0x77,0x1A,0x65,0x85,0x1C,0x74,0x93,0x1D,0x8F,0xA5,0x25, + 0xAD,0xB7,0x2C,0xBC,0xC7,0x30,0xC9,0xD5,0x33,0xD4,0xE0,0x3B, + 0xE0,0xEC,0x42,0xEA,0xF6,0x45,0xF0,0xFD,0x47,0xF4,0xFF,0x6F, + 0x55,0x24,0x00,0x5A,0x2C,0x00,0x6C,0x3B,0x00,0x79,0x4B,0x00, + 0xB9,0x75,0x00,0xBB,0x85,0x00,0xC1,0xA1,0x20,0xD0,0xB0,0x2F, + 0xDE,0xBE,0x3F,0xE6,0xC6,0x45,0xED,0xCD,0x57,0xF5,0xDB,0x62, + 0xFB,0xE5,0x69,0xFC,0xEE,0x6F,0xFD,0xF3,0x77,0xFD,0xF3,0x7F, + 0x5C,0x27,0x00,0x5C,0x2F,0x00,0x71,0x3B,0x00,0x7B,0x48,0x00, + 0xB9,0x68,0x20,0xBB,0x72,0x20,0xC5,0x86,0x29,0xD7,0x96,0x33, + 0xE6,0xA4,0x40,0xF4,0xB1,0x4B,0xFD,0xC1,0x58,0xFF,0xCC,0x55, + 0xFF,0xD4,0x61,0xFF,0xDD,0x69,0xFF,0xE6,0x79,0xFF,0xEA,0x98 +}; + +void palette_Load(const uint8_t* data) { + for (int index = 0; index < PALETTE_SIZE; index++) { + palette_data[index] = data[index]; + } +} diff --git a/core/Palette.h b/src/Palette.h old mode 100755 new mode 100644 similarity index 79% rename from core/Palette.h rename to src/Palette.h index df74e75..ac071d0 --- a/core/Palette.h +++ b/src/Palette.h @@ -5,7 +5,7 @@ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// // 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 @@ -24,19 +24,12 @@ // ---------------------------------------------------------------------------- #ifndef PALETTE_H #define PALETTE_H + #define PALETTE_SIZE 768 -#include -#include "Logger.h" - -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern bool palette_Load(std::string filename); -extern void palette_Load(const byte* data); -extern std::string palette_filename; -extern byte palette_data[PALETTE_SIZE]; +extern void palette_Load(const uint8_t* data); +extern const char *palette_filename; +extern uint8_t palette_data[PALETTE_SIZE]; extern bool palette_default; -#endif \ No newline at end of file +#endif diff --git a/src/Pokey.c b/src/Pokey.c new file mode 100644 index 0000000..938dded --- /dev/null +++ b/src/Pokey.c @@ -0,0 +1,500 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// PokeySound is Copyright(c) 1997 by Ron Fries +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of version 2 of the GNU Library General Public License +// as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library +// General Public License for more details. +// To obtain a copy of the GNU Library General Public License, write to the +// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// Any permitted reproduction of these routines, in whole or in part, must +// bear this legend. +// ---------------------------------------------------------------------------- +// Pokey.c +// ---------------------------------------------------------------------------- +#include +#include +#include + +#include "Pokey.h" +#include "ProSystem.h" + +#define POKEY_NOTPOLY5 0x80 +#define POKEY_POLY4 0x40 +#define POKEY_PURE 0x20 +#define POKEY_VOLUME_ONLY 0x10 +#define POKEY_VOLUME_MASK 0x0f +#define POKEY_POLY9 0x80 +#define POKEY_CH1_179 0x40 +#define POKEY_CH3_179 0x20 +#define POKEY_CH1_CH2 0x10 +#define POKEY_CH3_CH4 0x08 +#define POKEY_CH1_FILTER 0x04 +#define POKEY_CH2_FILTER 0x02 +#define POKEY_CLOCK_15 0x01 +#define POKEY_DIV_64 28 +#define POKEY_DIV_15 114 +#define POKEY_POLY4_SIZE 0x000f +#define POKEY_POLY5_SIZE 0x001f +#define POKEY_POLY9_SIZE 0x01ff +#define POKEY_POLY17_SIZE 0x0001ffff +#define POKEY_CHANNEL1 0 +#define POKEY_CHANNEL2 1 +#define POKEY_CHANNEL3 2 +#define POKEY_CHANNEL4 3 +#define POKEY_SAMPLE 4 + +#define SK_RESET 0x03 + +uint8_t pokey_buffer[POKEY_BUFFER_SIZE] = {0}; +uint32_t pokey_size = (POKEY_BUFFER_SIZE - 512); // 524 previously + +static uint32_t pokey_frequency = 1787520; +static uint32_t pokey_sampleRate = 31440; +static uint32_t pokey_soundCntr = 0; +static uint8_t pokey_audf[4]; +static uint8_t pokey_audc[4]; +static uint8_t pokey_audctl; +static uint8_t pokey_output[4]; +static uint8_t pokey_outVol[4]; +static uint8_t pokey_poly04[POKEY_POLY4_SIZE] = {1,1,0,1,1,1,0,0,0,0,1,0,1,0,0}; +static uint8_t pokey_poly05[POKEY_POLY5_SIZE] = {0,0,1,1,0,0,0,1,1,1,1,0,0,1,0,1,0,1,1,0,1,1,1,0,1,0,0,0,0,0,1}; +static uint8_t pokey_poly17[POKEY_POLY17_SIZE]; +static uint32_t pokey_poly17Size; +static uint32_t pokey_polyAdjust; +static uint32_t pokey_poly04Cntr; +static uint32_t pokey_poly05Cntr; +static uint32_t pokey_poly17Cntr; +static uint32_t pokey_divideMax[4]; +static uint32_t pokey_divideCount[4]; +static uint32_t pokey_sampleMax; +static uint32_t pokey_sampleCount[2]; +static uint32_t pokey_baseMultiplier; + +static uint8_t rand9[0x1ff]; +static uint8_t rand17[0x1ffff]; +static uint32_t r9; +static uint32_t r17; +static uint8_t SKCTL; +uint8_t RANDOM; + +uint8_t POT_input[8] = {228, 228, 228, 228, 228, 228, 228, 228}; +static int pot_scanline; + +static unsigned long long random_scanline_counter; +static unsigned long long prev_random_scanline_counter; + +static void rand_init(uint8_t *rng, int size, int left, int right, int add) { + int mask = (1 << size) - 1; + int i, x = 0; + + for (i = 0; i < mask; i++) { + if (size == 17) + *rng = x >> 6; // use bits 6..13 + else + *rng = x; // use bits 0..7 + rng++; + // calculate next bit + x = ((x << left) + (x >> right) + add) & mask; + } +} + +void pokey_setSampleRate( uint32_t rate ) { + pokey_sampleRate = rate; +} + +void pokey_Reset(void) { + pot_scanline = 0; + pokey_soundCntr = 0; + + for (int index = 0; index < POKEY_POLY17_SIZE; index++) { + pokey_poly17[index] = rand( ) & 1; + } + + pokey_polyAdjust = 0; + pokey_poly04Cntr = 0; + pokey_poly05Cntr = 0; + pokey_poly17Cntr = 0; + + pokey_sampleMax = ((uint32_t)pokey_frequency << 8) / pokey_sampleRate; + + pokey_sampleCount[0] = 0; + pokey_sampleCount[1] = 0; + + pokey_poly17Size = POKEY_POLY17_SIZE; + + for (int channel = POKEY_CHANNEL1; channel <= POKEY_CHANNEL4; channel++) { + pokey_outVol[channel] = 0; + pokey_output[channel] = 0; + pokey_divideCount[channel] = 0; + pokey_divideMax[channel] = 0x7fffffffL; + pokey_audc[channel] = 0; + pokey_audf[channel] = 0; + } + + for (int i = 0; i < 8; i++) { + POT_input[i] = 228; + } + + pokey_audctl = 0; + pokey_baseMultiplier = POKEY_DIV_64; + + // initialize the random arrays + rand_init(rand9, 9, 8, 1, 0x00180); + rand_init(rand17, 17,16, 1, 0x1c000); + + SKCTL = SK_RESET; + RANDOM = 0; + + r9 = 0; + r17 = 0; + random_scanline_counter = 0; + prev_random_scanline_counter = 0; +} + +// Called prior to each frame +void pokey_Frame(void) { +} + +// Called prior to each scanline +void pokey_Scanline(void) { + random_scanline_counter += CYCLES_PER_SCANLINE; + + if (pot_scanline < 228) + pot_scanline++; +} + +uint8_t pokey_GetRegister(uint16_t address) { + uint8_t data = 0; + + uint8_t addr = address & 0x0f; + if (addr < 8) { + uint8_t b = POT_input[addr]; + if (b <= pot_scanline) + return b; + return pot_scanline; + } + + switch (address) { + case POKEY_ALLPOT: { + uint8_t b = 0; + for (int i = 0; i < 8; i++) + if (POT_input[addr] <= pot_scanline) + b &= ~(1 << i); /* reset bit if pot value known */ + return b; + } + case POKEY_RANDOM: { + unsigned long long curr_scanline_counter = + (random_scanline_counter + prosystem_cycles + prosystem_extra_cycles); + + if (SKCTL & SK_RESET ) { + unsigned long long adjust = ((curr_scanline_counter - prev_random_scanline_counter) >> 2); + r9 = (uint32_t)((adjust + r9) % 0x001ff); + r17 = (uint32_t)((adjust + r17) % 0x1ffff); + } + else { + r9 = 0; + r17 = 0; + } + if (pokey_audctl & POKEY_POLY9) { + RANDOM = rand9[r9]; + } + else { + RANDOM = rand17[r17]; + } + + prev_random_scanline_counter = curr_scanline_counter; + RANDOM = RANDOM ^ 0xff; + data = RANDOM; + break; + } + } + + return data; +} + +void pokey_SetRegister(uint16_t address, uint8_t value) { + uint8_t channelMask; + + switch (address) { + case POKEY_POTGO: + if (!(SKCTL & 4)) + pot_scanline = 0; /* slow pot mode */ + return; + + case POKEY_SKCTLS: + SKCTL = value; + /* fast pot mode - return results immediately */ + if (value & 4) + pot_scanline = 228; + return; + + case POKEY_AUDF1: + pokey_audf[POKEY_CHANNEL1] = value; + channelMask = 1 << POKEY_CHANNEL1; + if (pokey_audctl & POKEY_CH1_CH2) { + channelMask |= 1 << POKEY_CHANNEL2; + } + break; + + case POKEY_AUDC1: + pokey_audc[POKEY_CHANNEL1] = value; + channelMask = 1 << POKEY_CHANNEL1; + break; + + case POKEY_AUDF2: + pokey_audf[POKEY_CHANNEL2] = value; + channelMask = 1 << POKEY_CHANNEL2; + break; + + case POKEY_AUDC2: + pokey_audc[POKEY_CHANNEL2] = value; + channelMask = 1 << POKEY_CHANNEL2; + break; + + case POKEY_AUDF3: + pokey_audf[POKEY_CHANNEL3] = value; + channelMask = 1 << POKEY_CHANNEL3; + + if (pokey_audctl & POKEY_CH3_CH4) { + channelMask |= 1 << POKEY_CHANNEL4; + } + break; + + case POKEY_AUDC3: + pokey_audc[POKEY_CHANNEL3] = value; + channelMask = 1 << POKEY_CHANNEL3; + break; + + case POKEY_AUDF4: + pokey_audf[POKEY_CHANNEL4] = value; + channelMask = 1 << POKEY_CHANNEL4; + break; + + case POKEY_AUDC4: + pokey_audc[POKEY_CHANNEL4] = value; + channelMask = 1 << POKEY_CHANNEL4; + break; + + case POKEY_AUDCTL: + pokey_audctl = value; + channelMask = 15; + if (pokey_audctl & POKEY_POLY9) { + pokey_poly17Size = POKEY_POLY9_SIZE; + } + else { + pokey_poly17Size = POKEY_POLY17_SIZE; + } + + if (pokey_audctl & POKEY_CLOCK_15) { + pokey_baseMultiplier = POKEY_DIV_15; + } + else { + pokey_baseMultiplier = POKEY_DIV_64; + } + break; + + default: + channelMask = 0; + break; + } + + uint32_t newValue = 0; + + if (channelMask & (1 << POKEY_CHANNEL1)) { + if (pokey_audctl & POKEY_CH1_179) { + newValue = pokey_audf[POKEY_CHANNEL1] + 4; + } + else { + newValue = (pokey_audf[POKEY_CHANNEL1] + 1) * pokey_baseMultiplier; + } + + if (newValue != pokey_divideMax[POKEY_CHANNEL1]) { + pokey_divideMax[POKEY_CHANNEL1] = newValue; + if(pokey_divideCount[POKEY_CHANNEL1] > newValue) { + pokey_divideCount[POKEY_CHANNEL1] = 0; + } + } + } + + if (channelMask & (1 << POKEY_CHANNEL2)) { + if (pokey_audctl & POKEY_CH1_CH2) { + if (pokey_audctl & POKEY_CH1_179) { + newValue = pokey_audf[POKEY_CHANNEL2] * 256 + pokey_audf[POKEY_CHANNEL1] + 7; + } + else { + newValue = (pokey_audf[POKEY_CHANNEL2] * 256 + pokey_audf[POKEY_CHANNEL1] + 1) * pokey_baseMultiplier; + } + } + else { + newValue = (pokey_audf[POKEY_CHANNEL2] + 1) * pokey_baseMultiplier; + } + if (newValue != pokey_divideMax[POKEY_CHANNEL2]) { + pokey_divideMax[POKEY_CHANNEL2] = newValue; + if (pokey_divideCount[POKEY_CHANNEL2] > newValue) { + pokey_divideCount[POKEY_CHANNEL2] = newValue; + } + } + } + + if (channelMask & (1 << POKEY_CHANNEL3)) { + if (pokey_audctl & POKEY_CH3_179) { + newValue = pokey_audf[POKEY_CHANNEL3] + 4; + } + else { + newValue= (pokey_audf[POKEY_CHANNEL3] + 1) * pokey_baseMultiplier; + } + + if (newValue!= pokey_divideMax[POKEY_CHANNEL3]) { + pokey_divideMax[POKEY_CHANNEL3] = newValue; + + if (pokey_divideCount[POKEY_CHANNEL3] > newValue) { + pokey_divideCount[POKEY_CHANNEL3] = newValue; + } + } + } + + if (channelMask & (1 << POKEY_CHANNEL4)) { + if (pokey_audctl & POKEY_CH3_CH4) { + if (pokey_audctl & POKEY_CH3_179) { + newValue = pokey_audf[POKEY_CHANNEL4] * 256 + pokey_audf[POKEY_CHANNEL3] + 7; + } + else { + newValue = (pokey_audf[POKEY_CHANNEL4] * 256 + pokey_audf[POKEY_CHANNEL3] + 1) * pokey_baseMultiplier; + } + } + else { + newValue = (pokey_audf[POKEY_CHANNEL4] + 1) * pokey_baseMultiplier; + } + + if (newValue != pokey_divideMax[POKEY_CHANNEL4]) { + pokey_divideMax[POKEY_CHANNEL4] = newValue; + + if (pokey_divideCount[POKEY_CHANNEL4] > newValue) { + pokey_divideCount[POKEY_CHANNEL4] = newValue; + } + } + } + + for (uint8_t channel = POKEY_CHANNEL1; channel <= POKEY_CHANNEL4; channel++) { + if (channelMask & (1 << channel)) { + if ((pokey_audc[channel] & POKEY_VOLUME_ONLY) || + ((pokey_audc[channel] & POKEY_VOLUME_MASK) == 0) || + (pokey_divideMax[channel] < (pokey_sampleMax >> 8))) { +#if 1 // WII + pokey_outVol[channel] = 1; +#else + pokey_outVol[channel] = pokey_audc[channel] & POKEY_VOLUME_MASK; +#endif + pokey_divideCount[channel] = 0x7fffffff; + pokey_divideMax[channel] = 0x7fffffff; + } + } + } +} + +void pokey_Process(uint32_t length) { + uint8_t* buffer = pokey_buffer + pokey_soundCntr; + uint32_t* sampleCntrPtr = (uint32_t*)((uint8_t*)(&pokey_sampleCount[0]) + 1); + uint32_t size = length; + + while(length) { + uint8_t currentValue; + uint8_t nextEvent = POKEY_SAMPLE; + uint32_t eventMin = *sampleCntrPtr; + + uint8_t channel; + + for (channel = POKEY_CHANNEL1; channel <= POKEY_CHANNEL4; channel++) { + if (pokey_divideCount[channel] <= eventMin) { + eventMin = pokey_divideCount[channel]; + nextEvent = channel; + } + } + + for(channel = POKEY_CHANNEL1; channel <= POKEY_CHANNEL4; channel++) { + pokey_divideCount[channel] -= eventMin; + } + + *sampleCntrPtr -= eventMin; + pokey_polyAdjust += eventMin; + + if (nextEvent != POKEY_SAMPLE) { + pokey_poly04Cntr = (pokey_poly04Cntr + pokey_polyAdjust) % POKEY_POLY4_SIZE; + pokey_poly05Cntr = (pokey_poly05Cntr + pokey_polyAdjust) % POKEY_POLY5_SIZE; + pokey_poly17Cntr = (pokey_poly17Cntr + pokey_polyAdjust) % pokey_poly17Size; + pokey_polyAdjust = 0; + pokey_divideCount[nextEvent] += pokey_divideMax[nextEvent]; + + if ((pokey_audc[nextEvent] & POKEY_NOTPOLY5) || pokey_poly05[pokey_poly05Cntr]) { + if (pokey_audc[nextEvent] & POKEY_PURE) { + pokey_output[nextEvent] = !pokey_output[nextEvent]; + } + else if (pokey_audc[nextEvent] & POKEY_POLY4) { + pokey_output[nextEvent] = pokey_poly04[pokey_poly04Cntr]; + } + else { + pokey_output[nextEvent] = pokey_poly17[pokey_poly17Cntr]; + } + } + + if (pokey_output[nextEvent]) { + pokey_outVol[nextEvent] = pokey_audc[nextEvent] & POKEY_VOLUME_MASK; + } + else { + pokey_outVol[nextEvent] = 0; + } + } + else { + *pokey_sampleCount += pokey_sampleMax; + currentValue = 0; + + for (channel = POKEY_CHANNEL1; channel <= POKEY_CHANNEL4; channel++) { + currentValue += pokey_outVol[channel]; + } + + currentValue = (currentValue << 2) + 8; + *buffer++ = currentValue; + length--; + } + } + + pokey_soundCntr += size; + + if (pokey_soundCntr >= pokey_size) { + pokey_soundCntr = 0; + } +} + +void pokey_Clear(void) { + for (int index = 0; index < POKEY_BUFFER_SIZE; index++) { + pokey_buffer[index] = 0; + } +} diff --git a/core/Pokey.h b/src/Pokey.h old mode 100755 new mode 100644 similarity index 64% rename from core/Pokey.h rename to src/Pokey.h index 1a1551f..87bf8bb --- a/core/Pokey.h +++ b/src/Pokey.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -21,25 +22,26 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // ---------------------------------------------------------------------------- // PokeySound is Copyright(c) 1997 by Ron Fries -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of version 2 of the GNU Library General Public License -// as published by the Free Software Foundation. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library -// General Public License for more details. -// To obtain a copy of the GNU Library General Public License, write to the -// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// -// Any permitted reproduction of these routines, in whole or in part, must -// bear this legend. +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of version 2 of the GNU Library General Public License +// as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library +// General Public License for more details. +// To obtain a copy of the GNU Library General Public License, write to the +// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// Any permitted reproduction of these routines, in whole or in part, must +// bear this legend. // ---------------------------------------------------------------------------- // Pokey.h // ---------------------------------------------------------------------------- #ifndef POKEY_H #define POKEY_H + #define POKEY_BUFFER_SIZE 624 #define POKEY_AUDF1 0x4000 #define POKEY_AUDC1 0x4001 @@ -72,21 +74,16 @@ #define POKEY_IRQST 0x400e #define POKEY_SKSTAT 0x400f -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; -typedef unsigned long long ulong; +extern void pokey_Reset(void); +extern void pokey_SetRegister(uint16_t address, uint8_t value); +extern uint8_t pokey_GetRegister(uint16_t address); +extern void pokey_Process(uint32_t length); +extern void pokey_Clear(void); +extern uint8_t pokey_buffer[POKEY_BUFFER_SIZE]; +extern uint32_t pokey_size; -extern void pokey_Reset( ); -extern void pokey_SetRegister(word address, byte value); -extern byte pokey_GetRegister(word address); -extern void pokey_Process(uint length); -extern void pokey_Clear( ); -extern byte pokey_buffer[POKEY_BUFFER_SIZE]; -extern uint pokey_size; - -extern void pokey_Frame(); -extern void pokey_Scanline(); -extern void pokey_setSampleRate(uint rate); +extern void pokey_Frame(void); +extern void pokey_Scanline(void); +extern void pokey_setSampleRate(uint32_t rate); #endif diff --git a/src/ProSystem.c b/src/ProSystem.c new file mode 100644 index 0000000..3b731b9 --- /dev/null +++ b/src/ProSystem.c @@ -0,0 +1,597 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2003, 2004 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// ProSystem.c +// ---------------------------------------------------------------------------- +#include +#include +#include +#include + +#include "ProSystem.h" +#define PRO_SYSTEM_STATE_HEADER "PRO-SYSTEM STATE" +#define PRO_SYSTEM_SOURCE "ProSystem.c" + +bool prosystem_active = false; +bool prosystem_paused = false; +uint16_t prosystem_frequency = 60; +uint8_t prosystem_frame = 0; +uint16_t prosystem_scanlines = 262; +uint32_t prosystem_cycles = 0; +uint32_t prosystem_extra_cycles = 0; +int lightgun_scanline = 0; +float lightgun_cycle = 0; + +// Whether the last CPU operation resulted in a half cycle (need to take it +// into consideration) +extern bool half_cycle; + +void prosystem_Reset(void) { + if (cartridge_IsLoaded()) { + prosystem_paused = false; + prosystem_frame = 0; + sally_Reset(); + region_Reset(); + tia_Clear(); + tia_Reset(); + pokey_Clear(); + pokey_Reset(); + xm_Reset(); + memory_Reset(); + maria_Clear(); + maria_Reset(); + riot_Reset(); + + if (bios_enabled) { + bios_Store(); + } + else { + cartridge_Store(); + } + + prosystem_cycles = sally_ExecuteRES(); + prosystem_active = true; + } +} + +// Strobe based on the current lightgun location +static void prosystem_FireLightGun(void) { + if (((maria_scanline >= lightgun_scanline) && + (maria_scanline <= ( lightgun_scanline + 3 ))) && + ((int)prosystem_cycles >= ((int)lightgun_cycle ) - 1 )) { + memory_ram[INPT4] &= 0x7f; + } + else { + memory_ram[INPT4] |= 0x80; + } +} + +void prosystem_ExecuteFrame(const uint8_t* input) { + // Is WSYNC enabled for the current frame? + bool wsync = !(cartridge_flags & CARTRIDGE_WSYNC_MASK); + + // Is Maria cycle stealing enabled for the current frame? + bool cycle_stealing = !(cartridge_flags & CARTRIDGE_CYCLE_STEALING_MASK); + + // Is the lightgun enabled for the current frame? + bool lightgun = ((cartridge_controller[0] & CARTRIDGE_CONTROLLER_LIGHTGUN) && (memory_ram[CTRL] & 96) != 64); + + riot_SetInput(input); + + prosystem_extra_cycles = 0; + + if (cartridge_pokey || cartridge_xm) pokey_Frame(); + + for (maria_scanline = 1; maria_scanline <= prosystem_scanlines; maria_scanline++) { + if (maria_scanline == maria_displayArea.top) { + memory_ram[MSTAT] = 0; + } + else if(maria_scanline == maria_displayArea.bottom) { + memory_ram[MSTAT] = 128; + } + + // Was a WSYNC performed withing the current scanline? + bool wsync_scanline = false; + + uint32_t cycles = 0; + + if (!cycle_stealing || (memory_ram[CTRL] & 96 ) != 64) { + // Exact cycle counts when Maria is disabled + prosystem_cycles %= CYCLES_PER_SCANLINE; + prosystem_extra_cycles = 0; + } + else { + prosystem_extra_cycles = (prosystem_cycles % CYCLES_PER_SCANLINE); + + // Some fudge for Maria cycles. Unfortunately Maria cycle counting + // isn't exact (This adds some extra cycles). + prosystem_cycles = 0; + } + + // If lightgun is enabled, check to see if it should be fired + if (lightgun) prosystem_FireLightGun(); + + while (prosystem_cycles < cartridge_hblank) { + cycles = sally_ExecuteInstruction( ); + prosystem_cycles += (cycles << 2); + + if (half_cycle) prosystem_cycles += 2; + + if (riot_timing) { + riot_UpdateTimer(cycles); + } + + // If lightgun is enabled, check to see if it should be fired + if (lightgun) prosystem_FireLightGun(); + + if (memory_ram[WSYNC] && wsync) { + memory_ram[WSYNC] = false; + wsync_scanline = true; + break; + } + } + + cycles = maria_RenderScanline( ); + + if (cycle_stealing) { + prosystem_cycles += cycles; + + if(riot_timing) { + riot_UpdateTimer(cycles >> 2); + } + } + + while (!wsync_scanline && prosystem_cycles < CYCLES_PER_SCANLINE) { + cycles = sally_ExecuteInstruction(); + prosystem_cycles += (cycles << 2); + + if(half_cycle) prosystem_cycles += 2; + + // If lightgun is enabled, check to see if it should be fired + if (lightgun) prosystem_FireLightGun(); + + if (riot_timing) { + riot_UpdateTimer(cycles); + } + + if(memory_ram[WSYNC] && wsync) { + memory_ram[WSYNC] = false; + wsync_scanline = true; + break; + } + } + + // If a WSYNC was performed and the current cycle count is less than + // the cycles per scanline, add those cycles to current timers. + if (wsync_scanline && prosystem_cycles < CYCLES_PER_SCANLINE) { + if (riot_timing) { + riot_UpdateTimer((CYCLES_PER_SCANLINE - prosystem_cycles) >> 2); + } + prosystem_cycles = CYCLES_PER_SCANLINE; + } + + // If lightgun is enabled, check to see if it should be fired + if (lightgun) prosystem_FireLightGun(); + + tia_Process(2); + + if (cartridge_pokey || cartridge_xm) { + pokey_Process(2); + } + + if (cartridge_pokey || cartridge_xm) pokey_Scanline(); + } + + prosystem_frame++; + + if (prosystem_frame >= prosystem_frequency) { + prosystem_frame = 0; + } +} + +bool prosystem_Save(const char *filename) { + uint8_t loc_buffer[33000 + XM_RAM_SIZE + 4] = {0}; + + uint32_t size = 0; + + uint32_t index; + + for (index = 0; index < 16; index++) { + loc_buffer[size + index] = PRO_SYSTEM_STATE_HEADER[index]; + } + size += 16; + + loc_buffer[size++] = 1; + for (index = 0; index < 4; index++) { + loc_buffer[size + index] = 0; + } + size += 4; + + for (index = 0; index < 32; index++) { + loc_buffer[size + index] = cart_digest[index]; + } + size += 32; + + loc_buffer[size++] = sally_a; + loc_buffer[size++] = sally_x; + loc_buffer[size++] = sally_y; + loc_buffer[size++] = sally_p; + loc_buffer[size++] = sally_s; + loc_buffer[size++] = sally_pc.b.l; + loc_buffer[size++] = sally_pc.b.h; + loc_buffer[size++] = cartridge_bank; + + for (index = 0; index < 16384; index++) { + loc_buffer[size + index] = memory_ram[index]; + } + size += 16384; + + if (cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM) { + for(index = 0; index < 16384; index++) { + loc_buffer[size + index] = memory_ram[16384 + index]; + } + size += 16384; + } + + // RIOT state + loc_buffer[size++] = riot_dra; + loc_buffer[size++] = riot_drb; + loc_buffer[size++] = riot_timing; + loc_buffer[size++] = ( 0xff & ( riot_timer >> 8 ) ); + loc_buffer[size++] = ( 0xff & riot_timer ); + loc_buffer[size++] = riot_intervals; + loc_buffer[size++] = ( 0xff & ( riot_clocks >> 8 ) ); + loc_buffer[size++] = ( 0xff & riot_clocks ); + + // XM (if applicable) + if (cartridge_xm) { + loc_buffer[size++] = xm_reg; + loc_buffer[size++] = xm_bank; + loc_buffer[size++] = xm_pokey_enabled; + loc_buffer[size++] = xm_mem_enabled; + + for (index = 0; index < XM_RAM_SIZE; index++) { + loc_buffer[size + index] = xm_ram[index]; + } + size += XM_RAM_SIZE; + } + + FILE* file = fopen(filename, "wb"); + if (file == NULL) { + return false; + } + + if (fwrite(loc_buffer, 1, size, file) != size) { + fclose(file); + return false; + } + + fflush(file); + fclose(file); + + return true; +} + +bool prosystem_Save_buffer(uint8_t *buffer) { + uint32_t size = 0; + uint32_t index; + + for (index = 0; index < 16; index++) { + buffer[size + index] = PRO_SYSTEM_STATE_HEADER[index]; + } + size += 16; + + buffer[size++] = 1; + for (index = 0; index < 4; index++) { + buffer[size + index] = 0; + } + size += 4; + + for (index = 0; index < 32; index++) { + buffer[size + index] = cart_digest[index]; + } + size += 32; + + buffer[size++] = sally_a; + buffer[size++] = sally_x; + buffer[size++] = sally_y; + buffer[size++] = sally_p; + buffer[size++] = sally_s; + buffer[size++] = sally_pc.b.l; + buffer[size++] = sally_pc.b.h; + buffer[size++] = cartridge_bank; + + for (index = 0; index < 16384; index++) { + buffer[size + index] = memory_ram[index]; + } + size += 16384; + + if (cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM) { + for (index = 0; index < 16384; index++) { + buffer[size + index] = memory_ram[16384 + index]; + } + size += 16384; + } + + // RIOT state + buffer[size++] = riot_dra; + buffer[size++] = riot_drb; + buffer[size++] = riot_timing; + buffer[size++] = ( 0xff & ( riot_timer >> 8 ) ); + buffer[size++] = ( 0xff & riot_timer ); + buffer[size++] = riot_intervals; + buffer[size++] = ( 0xff & ( riot_clocks >> 8 ) ); + buffer[size++] = ( 0xff & riot_clocks ); + + // XM (if applicable) + if (cartridge_xm) { + buffer[size++] = xm_reg; + buffer[size++] = xm_bank; + buffer[size++] = xm_pokey_enabled; + buffer[size++] = xm_mem_enabled; + + for (index = 0; index < XM_RAM_SIZE; index++) { + buffer[size + index] = xm_ram[index]; + } + size += XM_RAM_SIZE; + } + + return true; +} + +bool prosystem_Load(const char *filename) { + uint8_t loc_buffer[33000 + XM_RAM_SIZE + 4] = {0}; + + uint32_t size = 0; + if (size == 0) { + FILE* file = fopen(filename, "rb"); + if (file == NULL) { + return false; + } + + if (fseek(file, 0L, SEEK_END)) { + fclose(file); + return false; + } + + size = ftell(file); + if (fseek(file, 0L, SEEK_SET)) { + fclose(file); + return false; + } + + if (size != 16445 && size != 32829 && /* no RIOT */ + size != 16453 && size != 32837 && /* with RIOT */ + size != (16453 + 4 + XM_RAM_SIZE) && /* XM without supercart ram */ + size != (32837 + 4 + XM_RAM_SIZE)) /* XM with supercart ram */ + { + fclose(file); + return false; + } + + if (fread(loc_buffer, 1, size, file) != size && ferror(file)) { + fclose(file); + return false; + } + fclose(file); + } + + uint32_t offset = 0; + uint32_t index; + for (index = 0; index < 16; index++) { + if (loc_buffer[offset + index] != PRO_SYSTEM_STATE_HEADER[index]) { + return false; + } + } + offset += 16; + //uint8_t version = loc_buffer[offset++]; + offset++; + + for (index = 0; index < 4; index++) { + } + offset += 4; + + prosystem_Reset(); + + char digest[33] = {0}; + for (index = 0; index < 32; index++) { + digest[index] = loc_buffer[offset + index]; + } + offset += 32; + + if (strcmp(cart_digest, digest)) { // Not the same + return false; + } + + sally_a = loc_buffer[offset++]; + sally_x = loc_buffer[offset++]; + sally_y = loc_buffer[offset++]; + sally_p = loc_buffer[offset++]; + sally_s = loc_buffer[offset++]; + sally_pc.b.l = loc_buffer[offset++]; + sally_pc.b.h = loc_buffer[offset++]; + + cartridge_StoreBank(loc_buffer[offset++]); + + for(index = 0; index < 16384; index++) { + memory_ram[index] = loc_buffer[offset + index]; + } + offset += 16384; + + if (cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM) { + if (size != 32829 && /* no RIOT */ + size != 32837 && /* with RIOT */ + size != (32837 + 4 + XM_RAM_SIZE)) /* XM */ { + return false; + } + + for (index = 0; index < 16384; index++) { + memory_ram[16384 + index] = loc_buffer[offset + index]; + } + offset += 16384; + } + + if (size == 16453 || /* no supercart ram */ + size == 32837 || /* supercart ram */ + size == (16453 + 4 + XM_RAM_SIZE) || /* xm, no supercart ram */ + size == (32837 + 4 + XM_RAM_SIZE)) /* xm, supercart ram */ { + // RIOT state + riot_dra = loc_buffer[offset++]; + riot_drb = loc_buffer[offset++]; + riot_timing = loc_buffer[offset++]; + riot_timer = ( loc_buffer[offset++] << 8 ); + riot_timer |= loc_buffer[offset++]; + riot_intervals = loc_buffer[offset++]; + riot_clocks = ( loc_buffer[offset++] << 8 ); + riot_clocks |= loc_buffer[offset++]; + } + + // XM (if applicable) + if (cartridge_xm) { + if ((size != (16453 + 4 + XM_RAM_SIZE)) && + (size != (32837 + 4 + XM_RAM_SIZE))) { + return false; // Save state file has an invalid size + } + xm_reg = loc_buffer[offset++]; + xm_bank = loc_buffer[offset++]; + xm_pokey_enabled = loc_buffer[offset++]; + xm_mem_enabled = loc_buffer[offset++]; + + for (index = 0; index < XM_RAM_SIZE; index++) { + xm_ram[index] = loc_buffer[offset++]; + } + } + + return true; +} + +bool prosystem_Load_buffer(const uint8_t *buffer) { + uint32_t size = cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM ? 32837 : 16453; + if(cartridge_xm) { + size += 4 + XM_RAM_SIZE; + } + uint32_t offset = 0; + uint32_t index; + + for (index = 0; index < 16; index++) { + if (buffer[offset + index] != PRO_SYSTEM_STATE_HEADER[index]) { + return false; + } + } + offset += 16; + + //uint8_t version = buffer[offset++]; + offset++; + //uint32_t date = 0; + + offset += 4; + + //prosystem_Reset(); // TODO doesn't seem necessary but needs investigation + + char digest[33] = {0}; + for (index = 0; index < 32; index++) { + digest[index] = buffer[offset + index]; + } + offset += 32; + + if (strcmp(cart_digest, digest)) { // Not the same + return false; + } + + sally_a = buffer[offset++]; + sally_x = buffer[offset++]; + sally_y = buffer[offset++]; + sally_p = buffer[offset++]; + sally_s = buffer[offset++]; + sally_pc.b.l = buffer[offset++]; + sally_pc.b.h = buffer[offset++]; + + cartridge_StoreBank(buffer[offset++]); + + for (index = 0; index < 16384; index++) { + memory_ram[index] = buffer[offset + index]; + } + offset += 16384; + + if (cartridge_type == CARTRIDGE_TYPE_SUPERCART_RAM) { + if (size != 32829 && /* no RIOT */ + size != 32837 && /* with RIOT */ + size != (32837 + 4 + XM_RAM_SIZE)) /* XM */ { + return false; // Save state file has an invalid size. + } + for (index = 0; index < 16384; index++) { + memory_ram[16384 + index] = buffer[offset + index]; + } + offset += 16384; + } + + if (size == 16453 || /* no supercart ram */ + size == 32837 || /* supercart ram */ + size == (16453 + 4 + XM_RAM_SIZE) || /* xm, no supercart ram */ + size == (32837 + 4 + XM_RAM_SIZE)) /* xm, supercart ram */ { + // RIOT state + riot_dra = buffer[offset++]; + riot_drb = buffer[offset++]; + riot_timing = buffer[offset++]; + riot_timer = ( buffer[offset++] << 8 ); + riot_timer |= buffer[offset++]; + riot_intervals = buffer[offset++]; + riot_clocks = ( buffer[offset++] << 8 ); + riot_clocks |= buffer[offset++]; + } + + // XM (if applicable) + if (cartridge_xm) { + if ((size != (16453 + 4 + XM_RAM_SIZE)) && + (size != (32837 + 4 + XM_RAM_SIZE))) { + return false; // Save state file has an invalid size. + } + xm_reg = buffer[offset++]; + xm_bank = buffer[offset++]; + xm_pokey_enabled = buffer[offset++]; + xm_mem_enabled = buffer[offset++]; + + for (index = 0; index < XM_RAM_SIZE; index++) { + xm_ram[index] = buffer[offset++]; + } + } + + return true; +} + +void prosystem_Pause(bool pause) { + if (prosystem_active) { + prosystem_paused = pause; + } +} + +void prosystem_Close(void) { + prosystem_active = false; + prosystem_paused = false; + cartridge_Release(); + maria_Reset(); + maria_Clear(); + memory_Reset(); + tia_Reset(); + tia_Clear(); +} diff --git a/core/ProSystem.h b/src/ProSystem.h old mode 100755 new mode 100644 similarity index 69% rename from core/ProSystem.h rename to src/ProSystem.h index b652623..6dbbc3f --- a/core/ProSystem.h +++ b/src/ProSystem.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -25,8 +26,6 @@ #ifndef PRO_SYSTEM_H #define PRO_SYSTEM_H -#include -#include #include "Equates.h" #include "Bios.h" #include "Cartridge.h" @@ -35,14 +34,18 @@ #include "Region.h" #include "Riot.h" #include "Sally.h" -#include "Archive.h" #include "Tia.h" #include "Pokey.h" #include "ExpansionModule.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; +extern void prosystem_Reset(void); +extern void prosystem_ExecuteFrame(const uint8_t* input); +extern bool prosystem_Save(const char *filename); +extern bool prosystem_Load(const char *filename); +extern bool prosystem_Save_buffer(uint8_t *buffer); +extern bool prosystem_Load_buffer(const uint8_t *buffer); +extern void prosystem_Pause(bool pause); +extern void prosystem_Close(void); // The number of cycles per scan line #define CYCLES_PER_SCANLINE 454 @@ -53,21 +56,13 @@ typedef unsigned int uint; // The number of cycles indented (after HBLANK) prior to checking for a hit #define LG_CYCLES_INDENT 52 -extern void prosystem_Reset( ); -extern void prosystem_ExecuteFrame(const byte* input); -extern bool prosystem_Save(std::string filename, bool compress); -extern bool prosystem_Load(std::string filename); -extern bool prosystem_Save_buffer(byte *buffer); -extern bool prosystem_Load_buffer(const byte *buffer); -extern void prosystem_Pause(bool pause); -extern void prosystem_Close( ); extern bool prosystem_active; extern bool prosystem_paused; -extern word prosystem_frequency; -extern byte prosystem_frame; -extern word prosystem_scanlines; -extern uint prosystem_cycles; -extern uint prosystem_extra_cycles; +extern uint16_t prosystem_frequency; +extern uint8_t prosystem_frame; +extern uint16_t prosystem_scanlines; +extern uint32_t prosystem_cycles; +extern uint32_t prosystem_extra_cycles; // The scanline that the lightgun shot occurred at extern int lightgun_scanline; diff --git a/core/Timer.h b/src/Rect.h old mode 100755 new mode 100644 similarity index 71% rename from core/Timer.h rename to src/Rect.h index 85a92cb..dc815f7 --- a/core/Timer.h +++ b/src/Rect.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -20,17 +21,16 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // ---------------------------------------------------------------------------- -// Timer.h +// Rect.h // ---------------------------------------------------------------------------- -#ifndef TIMER_H -#define TIMER_H +#ifndef RECT_H +#define RECT_H -#include "ProSystem.h" -#include "Logger.h" -#include "Common.h" +typedef struct Rects { + uint32_t left; + uint32_t top; + uint32_t right; + uint32_t bottom; +} rect; -extern void timer_Initialize( ); -extern void timer_Reset( ); -extern bool timer_IsTime( ); - -#endif \ No newline at end of file +#endif diff --git a/src/Region.c b/src/Region.c new file mode 100644 index 0000000..e1047a4 --- /dev/null +++ b/src/Region.c @@ -0,0 +1,204 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// Region.c +// ---------------------------------------------------------------------------- +#include +#include + +#include "Region.h" + +uint8_t region_type = REGION_AUTO; + +static const rect REGION_DISPLAY_AREA_NTSC = {0, 16, 319, 258}; +static const rect REGION_VISIBLE_AREA_NTSC = {0, 26, 319, 250}; +static const uint8_t REGION_FREQUENCY_NTSC = 60; +static const uint16_t REGION_SCANLINES_NTSC = 262; + +static const rect REGION_DISPLAY_AREA_PAL = {0, 16, 319, 308}; +static const rect REGION_VISIBLE_AREA_PAL = {0, 26, 319, 297}; +static const uint8_t REGION_FREQUENCY_PAL = 50; +static const uint16_t REGION_SCANLINES_PAL = 312; + +static const uint8_t REGION_PALETTE_NTSC[] = { + 0x00,0x00,0x00,0x25,0x25,0x25,0x34,0x34,0x34,0x4F,0x4F,0x4F, + 0x5B,0x5B,0x5B,0x69,0x69,0x69,0x7B,0x7B,0x7B,0x8A,0x8A,0x8A, + 0xA7,0xA7,0xA7,0xB9,0xB9,0xB9,0xC5,0xC5,0xC5,0xD0,0xD0,0xD0, + 0xD7,0xD7,0xD7,0xE1,0xE1,0xE1,0xF4,0xF4,0xF4,0xFF,0xFF,0xFF, + 0x4C,0x32,0x00,0x62,0x3A,0x00,0x7B,0x4A,0x00,0x9A,0x60,0x00, + 0xB5,0x74,0x00,0xCC,0x85,0x00,0xE7,0x9E,0x08,0xF7,0xAF,0x10, + 0xFF,0xC3,0x18,0xFF,0xD0,0x20,0xFF,0xD8,0x28,0xFF,0xDF,0x30, + 0xFF,0xE6,0x3B,0xFF,0xF4,0x40,0xFF,0xFA,0x4B,0xFF,0xFF,0x50, + 0x99,0x25,0x00,0xAA,0x25,0x00,0xB4,0x25,0x00,0xD3,0x30,0x00, + 0xDD,0x48,0x02,0xE2,0x50,0x09,0xF4,0x67,0x00,0xF4,0x75,0x10, + 0xFF,0x9E,0x10,0xFF,0xAC,0x20,0xFF,0xBA,0x3A,0xFF,0xBF,0x50, + 0xFF,0xC6,0x6D,0xFF,0xD5,0x80,0xFF,0xE4,0x90,0xFF,0xE6,0x99, + 0x98,0x0C,0x0C,0x99,0x0C,0x0C,0xC2,0x13,0x00,0xD3,0x13,0x00, + 0xE2,0x35,0x00,0xE3,0x40,0x00,0xE4,0x40,0x20,0xE5,0x52,0x30, + 0xFD,0x78,0x54,0xFF,0x8A,0x6A,0xFF,0x98,0x7C,0xFF,0xA4,0x8B, + 0xFF,0xB3,0x9E,0xFF,0xC2,0xB2,0xFF,0xD0,0xBA,0xFF,0xD7,0xC0, + 0x99,0x00,0x00,0xA9,0x00,0x00,0xC2,0x04,0x00,0xD3,0x04,0x00, + 0xDA,0x04,0x00,0xDB,0x08,0x00,0xE4,0x20,0x20,0xF6,0x40,0x40, + 0xFB,0x70,0x70,0xFB,0x7E,0x7E,0xFB,0x8F,0x8F,0xFF,0x9F,0x9F, + 0xFF,0xAB,0xAB,0xFF,0xB9,0xB9,0xFF,0xC9,0xC9,0xFF,0xCF,0xCF, + 0x7E,0x00,0x50,0x80,0x00,0x50,0x80,0x00,0x5F,0x95,0x0B,0x74, + 0xAA,0x22,0x88,0xBB,0x2F,0x9A,0xCE,0x3F,0xAD,0xD7,0x5A,0xB6, + 0xE4,0x67,0xC3,0xEF,0x72,0xCE,0xFB,0x7E,0xDA,0xFF,0x8D,0xE1, + 0xFF,0x9D,0xE5,0xFF,0xA5,0xE7,0xFF,0xAF,0xEA,0xFF,0xB8,0xEC, + 0x48,0x00,0x6C,0x5C,0x04,0x88,0x65,0x0D,0x90,0x7B,0x23,0xA7, + 0x93,0x3B,0xBF,0x9D,0x45,0xC9,0xA7,0x4F,0xD3,0xB2,0x5A,0xDE, + 0xBD,0x65,0xE9,0xC5,0x6D,0xF1,0xCE,0x76,0xFA,0xD5,0x83,0xFF, + 0xDA,0x90,0xFF,0xDE,0x9C,0xFF,0xE2,0xA9,0xFF,0xE6,0xB6,0xFF, + 0x1B,0x00,0x70,0x22,0x1B,0x8D,0x37,0x30,0xA2,0x48,0x41,0xB3, + 0x59,0x52,0xC4,0x63,0x5C,0xCE,0x6F,0x68,0xDA,0x7D,0x76,0xE8, + 0x87,0x80,0xF8,0x93,0x8C,0xFF,0x9D,0x97,0xFF,0xA8,0xA3,0xFF, + 0xB3,0xAF,0xFF,0xBC,0xB8,0xFF,0xC4,0xC1,0xFF,0xDA,0xD1,0xFF, + 0x00,0x0D,0x7F,0x00,0x12,0xA7,0x00,0x18,0xC0,0x0A,0x2B,0xD1, + 0x1B,0x4A,0xE3,0x2F,0x58,0xF0,0x37,0x68,0xFF,0x49,0x79,0xFF, + 0x5B,0x85,0xFF,0x6D,0x96,0xFF,0x7F,0xA3,0xFF,0x8C,0xAD,0xFF, + 0x96,0xB4,0xFF,0xA8,0xC0,0xFF,0xB7,0xCB,0xFF,0xC6,0xD6,0xFF, + 0x00,0x29,0x5A,0x00,0x38,0x76,0x00,0x48,0x92,0x00,0x5C,0xAC, + 0x00,0x71,0xC6,0x00,0x86,0xD0,0x0A,0x9B,0xDF,0x1A,0xA8,0xEC, + 0x2B,0xB6,0xFF,0x3F,0xC2,0xFF,0x45,0xCB,0xFF,0x59,0xD3,0xFF, + 0x7F,0xDA,0xFF,0x8F,0xDE,0xFF,0xA0,0xE2,0xFF,0xB0,0xEB,0xFF, + 0x00,0x38,0x39,0x00,0x3C,0x48,0x00,0x3D,0x5B,0x02,0x66,0x7F, + 0x03,0x73,0x83,0x00,0x9C,0xAA,0x00,0xA1,0xBB,0x01,0xA4,0xCC, + 0x03,0xBB,0xFF,0x05,0xDA,0xE2,0x18,0xE5,0xFF,0x34,0xEA,0xFF, + 0x49,0xEF,0xFF,0x66,0xF2,0xFF,0x84,0xF4,0xFF,0x9E,0xF9,0xFF, + 0x00,0x4A,0x00,0x00,0x5D,0x00,0x00,0x70,0x00,0x00,0x8B,0x00, + 0x00,0xA9,0x00,0x00,0xBB,0x05,0x00,0xBD,0x00,0x02,0xD0,0x05, + 0x1A,0xD5,0x40,0x5A,0xF1,0x77,0x82,0xEF,0xA7,0x84,0xED,0xD1, + 0x89,0xFF,0xED,0x7D,0xFF,0xFF,0x93,0xFF,0xFF,0x9B,0xFF,0xFF, + 0x22,0x4A,0x03,0x27,0x53,0x04,0x30,0x64,0x05,0x3C,0x77,0x0C, + 0x45,0x8C,0x11,0x5A,0xA5,0x13,0x1B,0xD2,0x09,0x1F,0xDD,0x00, + 0x3D,0xCD,0x2D,0x3D,0xCD,0x30,0x58,0xCC,0x40,0x60,0xD3,0x50, + 0xA2,0xEC,0x55,0xB3,0xF2,0x4A,0xBB,0xF6,0x5D,0xC4,0xF8,0x70, + 0x2E,0x3F,0x0C,0x36,0x4A,0x0F,0x40,0x56,0x15,0x46,0x5F,0x17, + 0x57,0x77,0x1A,0x65,0x85,0x1C,0x74,0x93,0x1D,0x8F,0xA5,0x25, + 0xAD,0xB7,0x2C,0xBC,0xC7,0x30,0xC9,0xD5,0x33,0xD4,0xE0,0x3B, + 0xE0,0xEC,0x42,0xEA,0xF6,0x45,0xF0,0xFD,0x47,0xF4,0xFF,0x6F, + 0x55,0x24,0x00,0x5A,0x2C,0x00,0x6C,0x3B,0x00,0x79,0x4B,0x00, + 0xB9,0x75,0x00,0xBB,0x85,0x00,0xC1,0xA1,0x20,0xD0,0xB0,0x2F, + 0xDE,0xBE,0x3F,0xE6,0xC6,0x45,0xED,0xCD,0x57,0xF5,0xDB,0x62, + 0xFB,0xE5,0x69,0xFC,0xEE,0x6F,0xFD,0xF3,0x77,0xFD,0xF3,0x7F, + 0x5C,0x27,0x00,0x5C,0x2F,0x00,0x71,0x3B,0x00,0x7B,0x48,0x00, + 0xB9,0x68,0x20,0xBB,0x72,0x20,0xC5,0x86,0x29,0xD7,0x96,0x33, + 0xE6,0xA4,0x40,0xF4,0xB1,0x4B,0xFD,0xC1,0x58,0xFF,0xCC,0x55, + 0xFF,0xD4,0x61,0xFF,0xDD,0x69,0xFF,0xE6,0x79,0xFF,0xEA,0x98 +}; + +static const uint8_t REGION_PALETTE_PAL[] = { + 0x00,0x00,0x00,0x1c,0x1c,0x1c,0x39,0x39,0x39,0x59,0x59,0x59, + 0x79,0x79,0x79,0x92,0x92,0x92,0xab,0xab,0xab,0xbc,0xbc,0xbc, + 0xcd,0xcd,0xcd,0xd9,0xd9,0xd9,0xe6,0xe6,0xe6,0xec,0xec,0xec, + 0xf2,0xf2,0xf2,0xf8,0xf8,0xf8,0xff,0xff,0xff,0xff,0xff,0xff, + 0x26,0x30,0x01,0x24,0x38,0x03,0x23,0x40,0x05,0x51,0x54,0x1b, + 0x80,0x69,0x31,0x97,0x81,0x35,0xaf,0x99,0x3a,0xc2,0xa7,0x3e, + 0xd5,0xb5,0x43,0xdb,0xc0,0x3d,0xe1,0xcb,0x38,0xe2,0xd8,0x36, + 0xe3,0xe5,0x34,0xef,0xf2,0x58,0xfb,0xff,0x7d,0xfb,0xff,0x7d, + 0x39,0x17,0x01,0x5e,0x23,0x04,0x83,0x30,0x08,0xa5,0x47,0x16, + 0xc8,0x5f,0x24,0xe3,0x78,0x20,0xff,0x91,0x1d,0xff,0xab,0x1d, + 0xff,0xc5,0x1d,0xff,0xce,0x34,0xff,0xd8,0x4c,0xff,0xe6,0x51, + 0xff,0xf4,0x56,0xff,0xf9,0x77,0xff,0xff,0x98,0xff,0xff,0x98, + 0x45,0x19,0x04,0x72,0x1e,0x11,0x9f,0x24,0x1e,0xb3,0x3a,0x20, + 0xc8,0x51,0x22,0xe3,0x69,0x20,0xff,0x81,0x1e,0xff,0x8c,0x25, + 0xff,0x98,0x2c,0xff,0xae,0x38,0xff,0xc5,0x45,0xff,0xc5,0x59, + 0xff,0xc6,0x6d,0xff,0xd5,0x87,0xff,0xe4,0xa1,0xff,0xe4,0xa1, + 0x4a,0x17,0x04,0x7e,0x1a,0x0d,0xb2,0x1d,0x17,0xc8,0x21,0x19, + 0xdf,0x25,0x1c,0xec,0x3b,0x38,0xfa,0x52,0x55,0xfc,0x61,0x61, + 0xff,0x70,0x6e,0xff,0x7f,0x7e,0xff,0x8f,0x8f,0xff,0x9d,0x9e, + 0xff,0xab,0xad,0xff,0xb9,0xbd,0xff,0xc7,0xce,0xff,0xc7,0xce, + 0x05,0x05,0x68,0x3b,0x13,0x6d,0x71,0x22,0x72,0x8b,0x2a,0x8c, + 0xa5,0x32,0xa6,0xb9,0x38,0xba,0xcd,0x3e,0xcf,0xdb,0x47,0xdd, + 0xea,0x51,0xeb,0xf4,0x5f,0xf5,0xfe,0x6d,0xff,0xfe,0x7a,0xfd, + 0xff,0x87,0xfb,0xff,0x95,0xfd,0xff,0xa4,0xff,0xff,0xa4,0xff, + 0x28,0x04,0x79,0x40,0x09,0x84,0x59,0x0f,0x90,0x70,0x24,0x9d, + 0x88,0x39,0xaa,0xa4,0x41,0xc3,0xc0,0x4a,0xdc,0xd0,0x54,0xed, + 0xe0,0x5e,0xff,0xe9,0x6d,0xff,0xf2,0x7c,0xff,0xf8,0x8a,0xff, + 0xff,0x98,0xff,0xfe,0xa1,0xff,0xfe,0xab,0xff,0xfe,0xab,0xff, + 0x35,0x08,0x8a,0x42,0x0a,0xad,0x50,0x0c,0xd0,0x64,0x28,0xd0, + 0x79,0x45,0xd0,0x8d,0x4b,0xd4,0xa2,0x51,0xd9,0xb0,0x58,0xec, + 0xbe,0x60,0xff,0xc5,0x6b,0xff,0xcc,0x77,0xff,0xd1,0x83,0xff, + 0xd7,0x90,0xff,0xdb,0x9d,0xff,0xdf,0xaa,0xff,0xdf,0xaa,0xff, + 0x05,0x1e,0x81,0x06,0x26,0xa5,0x08,0x2f,0xca,0x26,0x3d,0xd4, + 0x44,0x4c,0xde,0x4f,0x5a,0xee,0x5a,0x68,0xff,0x65,0x75,0xff, + 0x71,0x83,0xff,0x80,0x91,0xff,0x90,0xa0,0xff,0x97,0xa9,0xff, + 0x9f,0xb2,0xff,0xaf,0xbe,0xff,0xc0,0xcb,0xff,0xc0,0xcb,0xff, + 0x05,0x1e,0x81,0x06,0x26,0xa5,0x08,0x2f,0xca,0x26,0x3d,0xd4, + 0x44,0x4c,0xde,0x4f,0x5a,0xee,0x5a,0x68,0xff,0x65,0x75,0xff, + 0x71,0x83,0xff,0x80,0x91,0xff,0x90,0xa0,0xff,0x97,0xa9,0xff, + 0x9f,0xb2,0xff,0xaf,0xbe,0xff,0xc0,0xcb,0xff,0xc0,0xcb,0xff, + 0x0c,0x04,0x8b,0x22,0x18,0xa0,0x38,0x2d,0xb5,0x48,0x3e,0xc7, + 0x58,0x4f,0xda,0x61,0x59,0xec,0x6b,0x64,0xff,0x7a,0x74,0xff, + 0x8a,0x84,0xff,0x91,0x8e,0xff,0x99,0x98,0xff,0xa5,0xa3,0xff, + 0xb1,0xae,0xff,0xb8,0xb8,0xff,0xc0,0xc2,0xff,0xc0,0xc2,0xff, + 0x1d,0x29,0x5a,0x1d,0x38,0x76,0x1d,0x48,0x92,0x1c,0x5c,0xac, + 0x1c,0x71,0xc6,0x32,0x86,0xcf,0x48,0x9b,0xd9,0x4e,0xa8,0xec, + 0x55,0xb6,0xff,0x70,0xc7,0xff,0x8c,0xd8,0xff,0x93,0xdb,0xff, + 0x9b,0xdf,0xff,0xaf,0xe4,0xff,0xc3,0xe9,0xff,0xc3,0xe9,0xff, + 0x2f,0x43,0x02,0x39,0x52,0x02,0x44,0x61,0x03,0x41,0x7a,0x12, + 0x3e,0x94,0x21,0x4a,0x9f,0x2e,0x57,0xab,0x3b,0x5c,0xbd,0x55, + 0x61,0xd0,0x70,0x69,0xe2,0x7a,0x72,0xf5,0x84,0x7c,0xfa,0x8d, + 0x87,0xff,0x97,0x9a,0xff,0xa6,0xad,0xff,0xb6,0xad,0xff,0xb6, + 0x0a,0x41,0x08,0x0d,0x54,0x0a,0x10,0x68,0x0d,0x13,0x7d,0x0f, + 0x16,0x92,0x12,0x19,0xa5,0x14,0x1c,0xb9,0x17,0x1e,0xc9,0x19, + 0x21,0xd9,0x1b,0x47,0xe4,0x2d,0x6e,0xf0,0x40,0x78,0xf7,0x4d, + 0x83,0xff,0x5b,0x9a,0xff,0x7a,0xb2,0xff,0x9a,0xb2,0xff,0x9a, + 0x04,0x41,0x0b,0x05,0x53,0x0e,0x06,0x66,0x11,0x07,0x77,0x14, + 0x08,0x88,0x17,0x09,0x9b,0x1a,0x0b,0xaf,0x1d,0x48,0xc4,0x1f, + 0x86,0xd9,0x22,0x8f,0xe9,0x24,0x99,0xf9,0x27,0xa8,0xfc,0x41, + 0xb7,0xff,0x5b,0xc9,0xff,0x6e,0xdc,0xff,0x81,0xdc,0xff,0x81, + 0x02,0x35,0x0f,0x07,0x3f,0x15,0x0c,0x4a,0x1c,0x2d,0x5f,0x1e, + 0x4f,0x74,0x20,0x59,0x83,0x24,0x64,0x92,0x28,0x82,0xa1,0x2e, + 0xa1,0xb0,0x34,0xa9,0xc1,0x3a,0xb2,0xd2,0x41,0xc4,0xd9,0x45, + 0xd6,0xe1,0x49,0xe4,0xf0,0x4e,0xf2,0xff,0x53,0xf2,0xff,0x53, +}; + +void region_Reset(void) { + if (region_type == REGION_PAL || (region_type == REGION_AUTO && cartridge_region == REGION_PAL)) { + maria_displayArea = REGION_DISPLAY_AREA_PAL; + maria_visibleArea = REGION_VISIBLE_AREA_PAL; + + if (palette_default) // Added check for default - bberlin + palette_Load(REGION_PALETTE_PAL); + + prosystem_frequency = REGION_FREQUENCY_PAL; + prosystem_scanlines = REGION_SCANLINES_PAL; + tia_size = 624; + pokey_size = 624; + } + else { + maria_displayArea = REGION_DISPLAY_AREA_NTSC; + maria_visibleArea = REGION_VISIBLE_AREA_NTSC; + + if (palette_default) // Added check for default - bberlin + palette_Load(REGION_PALETTE_NTSC); + + prosystem_frequency = REGION_FREQUENCY_NTSC; + prosystem_scanlines = REGION_SCANLINES_NTSC; + tia_size = 524; + pokey_size = 524; + } + + pokey_setSampleRate((prosystem_scanlines * prosystem_frequency) << 1); +} diff --git a/core/Region.h b/src/Region.h old mode 100755 new mode 100644 similarity index 78% rename from core/Region.h rename to src/Region.h index f9bec67..a6af311 --- a/core/Region.h +++ b/src/Region.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -24,6 +25,7 @@ // ---------------------------------------------------------------------------- #ifndef REGION_H #define REGION_H + #define REGION_NTSC 0 #define REGION_PAL 1 #define REGION_AUTO 2 @@ -34,11 +36,7 @@ #include "Palette.h" #include "Tia.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; +extern void region_Reset(void); +extern uint8_t region_type; -extern void region_Reset( ); -extern byte region_type; - -#endif \ No newline at end of file +#endif diff --git a/src/Riot.c b/src/Riot.c new file mode 100644 index 0000000..e66e275 --- /dev/null +++ b/src/Riot.c @@ -0,0 +1,257 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// Riot.c +// ---------------------------------------------------------------------------- +#include +#include +#include + +#include "Riot.h" + +bool riot_timing = false; +uint16_t riot_timer = TIM64T; +uint8_t riot_intervals; + +uint8_t riot_dra = 0; +uint8_t riot_drb = 0; +static bool riot_elapsed; +static int riot_currentTime; +uint16_t riot_clocks; + +void riot_Reset(void) { + riot_SetDRA(0); + riot_SetDRB(0); + + riot_timing = false; + riot_timer = TIM64T; + riot_intervals = 0; + riot_clocks = 0; + + riot_elapsed = false; + riot_currentTime = 0; +} + +// ---------------------------------------------------------------------------- +// SetInput +// +----------+--------------+------------------------------------------------- +// | Offset | Controller | Control +// +----------+--------------+------------------------------------------------- +// | 00 | Joystick 1 | Right +// | 01 | Joystick 1 | Left +// | 02 | Joystick 1 | Down +// | 03 | Joystick 1 | Up +// | 04 | Joystick 1 | Button 1 +// | 05 | Joystick 1 | Button 2 +// | 06 | Joystick 2 | Right +// | 07 | Joystick 2 | Left +// | 08 | Joystick 2 | Down +// | 09 | Joystick 2 | Up +// | 10 | Joystick 2 | Button 1 +// | 11 | Joystick 2 | Button 2 +// | 12 | Console | Reset +// | 13 | Console | Select +// | 14 | Console | Pause +// | 15 | Console | Left Difficulty +// | 16 | Console | Right Difficulty +// +----------+--------------+------------------------------------------------- +void riot_SetInput(const uint8_t* input) { + + /*gdement: Comments are messy, but wanted to document how this all works. + Changed this routine to support 1 vs 2 button modes. + Also added the interaction of CTLSWA and DRA on the SWCHA output, and same + for SWCHB. SWCHA is directionals. SWCHB is console switches and button + mode. Button signals are in high bits of INPT0-5.*/ + + memory_ram[SWCHA] = ((~memory_ram[CTLSWA]) | riot_dra); /*SWCHA as driven by RIOT*/ + /*now console switches will force bits to ground:*/ + if (input[0x00]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x80; + if (input[0x01]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x40; + if (input[0x02]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x20; + if (input[0x03]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x10; + if (input[0x06]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x08; + if (input[0x07]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x04; + if (input[0x08]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x02; + if (input[0x09]) memory_ram[SWCHA] = memory_ram[SWCHA] &~ 0x01; + /*Switches can always push the appropriate bit of SWCHA to ground, as in above code block. + In addition, RIOT can be configured to drive ground even when switch is open. + By doing this it's possible for real hardware to behave as if switches are permanently held (tested this).*/ + + /*As with swcha, the value seen at SWCHB is derived from CTLSWB and DRB (an internal RIOT register) + (Any write to SWCHB actually gets stored in DRB) + If a given bit in CTLSWB is 0 (input mode), then RIOT puts a 1 on SWCHB. + If bit in CTLSWB is 1 (output mode), then RIOT puts stored DRB value on SWCHB. + The SWCHB outputs from RIOT can be overdriven to 0 by console switches. + The CTLSWB/DRB interaction is important at bits 2 and 4, which control button mode for each player. + Bit 5 appears unused, and other bits are the console switches. + + CTLSWB DRB SWCHB result on button mode (for bits 2 and 4) + ------- --- ----- ----------------------------------------- + 0 0 1 1 button mode - this is default state after boot + 0 1 1 1 button mode + 1 0 0 2 button mode + 1 1 1 1 button mode + This chart was confirmed on hardware + From the default state after boot, simply changing CTLSWB to 1 will result in 2 button mode. + Some games rely on this, and don't actually store anything to SWCHB.*/ + + memory_ram[SWCHB] = ((~memory_ram[CTLSWB]) | riot_drb); /*SWCHB as driven by RIOT*/ + + if (input != NULL) { + /*now the console switches can force certain bits to ground:*/ + if (input[0x0c]) memory_ram[SWCHB] = memory_ram[SWCHB] &~ 0x01; + if (input[0x0d]) memory_ram[SWCHB] = memory_ram[SWCHB] &~ 0x02; + if (input[0x0e]) memory_ram[SWCHB] = memory_ram[SWCHB] &~ 0x08; + if (input[0x0f]) memory_ram[SWCHB] = memory_ram[SWCHB] &~ 0x40; + if (input[0x10]) memory_ram[SWCHB] = memory_ram[SWCHB] &~ 0x80; + } + + /*When in 1 button mode, only the legacy 2600 button signal is active. The others stay off. + When in 2 button mode, only the new signals are active. 2600 button stays off. (tested) + see: http://www.atariage.com/forums/index.php?showtopic=127162 + also see 7800 schematic and RIOT datasheet */ + + if (memory_ram[SWCHB] & 0x04) { //first player in 1 button mode + memory_ram[INPT0] &= 0x7f; //new style buttons are always off in this mode + memory_ram[INPT1] &= 0x7f; + + //in this mode, either button triggers only the legacy button signal + if (input[0x04] || input[0x05]) { + memory_ram[INPT4] &= 0x7f; //this button signal activates by turning off the high bit + } + else { + memory_ram[INPT4] |= 0x80; + } + } + else { //first player in 2 button mode + memory_ram[INPT4] |= 0x80; //2600 button is always off in this mode + if (input[0x04]) { //left button (button 1) + memory_ram[INPT1] |= 0x80; //these buttons activate by turning on the high bit. + } + else { + memory_ram[INPT1] &= 0x7f; + } + if (input[0x05]) { //right button (button 2) + memory_ram[INPT0] |= 0x80; + } + else { + memory_ram[INPT0] &= 0x7f; + } + } + + /*now repeat for 2nd player*/ + if (memory_ram[SWCHB] & 0x10) { + memory_ram[INPT2] &= 0x7f; + memory_ram[INPT3] &= 0x7f; + + if (input[0x0a] || input[0x0b]) { + memory_ram[INPT5] &= 0x7f; + } + else { + memory_ram[INPT5] |= 0x80; + } + } + else { + memory_ram[INPT5] |= 0x80; + + if (input[0x0a]) { + memory_ram[INPT3] |= 0x80; + } + else { + memory_ram[INPT3] &= 0x7f; + } + + if (input[0x0b]) { + memory_ram[INPT2] |= 0x80; + } + else { + memory_ram[INPT2] &= 0x7f; + } + } +} + +/*Stores a value written to SWCHA/SWCHB into the RIOT's internal DRA/DRB +registers. These are distinct from what you see when reading SWCHA/SWCHB.*/ +void riot_SetDRA(uint8_t data) { + riot_dra=data; +} + +void riot_SetDRB(uint8_t data) { + riot_drb=data; +} + +void riot_SetTimer(uint16_t timer, uint8_t intervals) { + riot_timer = timer; + riot_intervals = intervals; + + switch (timer) { + case T1024T: + riot_clocks = 1024; + riot_timing = true; + break; + + case TIM1T: + riot_clocks = 1; + riot_timing = true; + break; + + case TIM8T: + riot_clocks = 8; + riot_timing = true; + break; + + case TIM64T: + riot_clocks = 64; + riot_timing = true; + break; + } + + if (riot_timing) { + riot_currentTime = riot_clocks * intervals; + riot_elapsed = false; + } +} + +void riot_UpdateTimer(uint8_t cycles) { + riot_currentTime -= cycles; + if (!riot_elapsed && riot_currentTime > 0) { + memory_Write(INTIM, riot_currentTime / riot_clocks); + } + else { + if (riot_elapsed) { + if(riot_currentTime >= -255) { + memory_Write(INTIM, riot_currentTime); + } + else { + memory_Write(INTIM, 0); + riot_timing = false; + } + } + else { + riot_currentTime = riot_clocks; + memory_Write(INTIM, 0); + memory_ram[INTFLG] |= 0x80; + riot_elapsed = true; + } + } +} diff --git a/core/Riot.h b/src/Riot.h old mode 100755 new mode 100644 similarity index 64% rename from core/Riot.h rename to src/Riot.h index 920eb76..a7e0a20 --- a/core/Riot.h +++ b/src/Riot.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -28,21 +29,17 @@ #include "Equates.h" #include "Memory.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - extern void riot_Reset(void); -extern void riot_SetInput(const byte* input); -extern void riot_SetDRA(byte data); -extern void riot_SetDRB(byte data); -extern void riot_SetTimer(word timer, byte intervals); -extern void riot_UpdateTimer(byte cycles); +extern void riot_SetInput(const uint8_t* input); +extern void riot_SetDRA(uint8_t data); +extern void riot_SetDRB(uint8_t data); +extern void riot_SetTimer(uint16_t timer, uint8_t intervals); +extern void riot_UpdateTimer(uint8_t cycles); extern bool riot_timing; -extern word riot_timer; -extern byte riot_intervals; -extern byte riot_dra; -extern byte riot_drb; -extern word riot_clocks; +extern uint16_t riot_timer; +extern uint8_t riot_intervals; +extern uint8_t riot_dra; +extern uint8_t riot_drb; +extern uint16_t riot_clocks; #endif diff --git a/src/Sally.c b/src/Sally.c new file mode 100644 index 0000000..a9526e0 --- /dev/null +++ b/src/Sally.c @@ -0,0 +1,1534 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// Sally.c +// ---------------------------------------------------------------------------- +#include +#include + +#include "Sally.h" + +uint8_t sally_a = 0; +uint8_t sally_x = 0; +uint8_t sally_y = 0; +uint8_t sally_p = 0; +uint8_t sally_s = 0; +pair sally_pc = {0}; + +static uint8_t sally_opcode; +static pair sally_address; +static uint32_t sally_cycles; + +// Whether the last operation resulted in a half cycle. (needs to be taken +// into consideration by ProSystem when cycle counting). This can occur when +// a TIA or RIOT are accessed (drops to 1.19Mhz when the TIA or RIOT chips +// are accessed) +bool half_cycle = false; + +typedef struct Flag { + uint8_t C; + uint8_t Z; + uint8_t I; + uint8_t D; + uint8_t B; + uint8_t R; + uint8_t V; + uint8_t N; +} Flag; + +static const Flag SALLY_FLAG = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; + +typedef struct Vector { + uint16_t H; + uint16_t L; +} Vector; + +static const Vector SALLY_RES = {65533, 65532}; +static const Vector SALLY_NMI = {65531, 65530}; +static const Vector SALLY_IRQ = {65535, 65534}; + +static const uint8_t SALLY_CYCLES[256] = { + 7,6,0,0,0,3,5,0,3,2,2,2,0,4,6,0, + 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, + 6,6,0,0,3,3,5,0,4,2,2,2,4,4,6,0, + 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, + 6,6,0,0,0,3,5,0,3,2,2,2,3,4,6,0, + 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, + 6,6,0,0,0,3,5,0,4,2,2,0,5,4,6,0, + 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, + 0,6,0,0,3,3,3,0,2,0,2,0,4,4,4,0, + 2,6,0,0,4,4,4,0,2,5,2,0,0,5,0,0, + 2,6,2,0,3,3,3,0,2,2,2,0,4,4,4,0, + 2,5,0,0,4,4,4,0,2,4,2,0,4,4,4,0, + 2,6,0,0,3,3,5,0,2,2,2,0,4,4,6,0, + 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, + 2,6,0,0,3,3,5,0,2,2,2,0,4,4,6,0, + 2,5,0,0,0,4,6,0,2,4,0,0,0,4,7,0, +}; + +static void sally_Push(uint8_t data) { + memory_Write(sally_s + 256, data); + sally_s--; +} + +static uint8_t sally_Pop(void) { + sally_s++; + return memory_Read(sally_s + 256); +} + +static void sally_Flags(uint8_t data) { + if (!data) { + sally_p |= SALLY_FLAG.Z; + } + else { + sally_p &= ~SALLY_FLAG.Z; + } + + if (data & 128) { + sally_p |= SALLY_FLAG.N; + } + else { + sally_p &= ~SALLY_FLAG.N; + } +} + +static void sally_Branch(uint8_t branch) { + if (branch) { + pair temp = sally_pc; + sally_pc.w += (signed char)sally_address.b.l; + + if (temp.b.h != sally_pc.b.h) { + sally_cycles += 2; + } + else { + sally_cycles++; + } + } +} + +static void sally_Delay(uint8_t delta) { + pair address1 = sally_address; + pair address2 = sally_address; + address1.w -= delta; + + if (address1.b.h != address2.b.h) { + sally_cycles++; + } +} + +static void sally_Absolute(void) { + sally_address.b.l = memory_Read(sally_pc.w++); + sally_address.b.h = memory_Read(sally_pc.w++); +} + +static void sally_AbsoluteX(void) { + sally_address.b.l = memory_Read(sally_pc.w++); + sally_address.b.h = memory_Read(sally_pc.w++); + sally_address.w += sally_x; +} + +static void sally_AbsoluteY(void) { + sally_address.b.l = memory_Read(sally_pc.w++); + sally_address.b.h = memory_Read(sally_pc.w++); + sally_address.w += sally_y; +} + +static void sally_Immediate(void) { + sally_address.w = sally_pc.w++; +} + +static void sally_Indirect(void) { + pair base; + base.b.l = memory_Read(sally_pc.w++); + base.b.h = memory_Read(sally_pc.w++); + sally_address.b.l = memory_Read(base.w); + sally_address.b.h = memory_Read(base.w + 1); +} + +static void sally_IndirectX(void) { + sally_address.b.l = memory_Read(sally_pc.w++) + sally_x; + sally_address.b.h = memory_Read(sally_address.b.l + 1); + sally_address.b.l = memory_Read(sally_address.b.l); +} + +static void sally_IndirectY(void) { + sally_address.b.l = memory_Read(sally_pc.w++); + sally_address.b.h = memory_Read(sally_address.b.l + 1); + sally_address.b.l = memory_Read(sally_address.b.l); + sally_address.w += sally_y; +} + +static void sally_Relative(void) { + sally_address.w = memory_Read(sally_pc.w++); +} + +static void sally_ZeroPage(void) { + sally_address.w = memory_Read(sally_pc.w++); +} + +static void sally_ZeroPageX(void) { + sally_address.w = memory_Read(sally_pc.w++); + sally_address.b.l += sally_x; +} + +static void sally_ZeroPageY(void) { + sally_address.w = memory_Read(sally_pc.w++); + sally_address.b.l += sally_y; +} + +static void sally_ADC(void) { + uint8_t data = memory_Read(sally_address.w); + + if (sally_p & SALLY_FLAG.D) { + uint16_t al = (sally_a & 15) + (data & 15) + (sally_p & SALLY_FLAG.C); + uint16_t ah = (sally_a >> 4) + (data >> 4); + + if (al > 9) { + al += 6; + ah++; + } + + if (!(sally_a + data + (sally_p & SALLY_FLAG.C))) { + sally_p |= SALLY_FLAG.Z; + } + else { + sally_p &= ~SALLY_FLAG.Z; + } + + if ((ah & 8) != 0) { + sally_p |= SALLY_FLAG.N; + } + else { + sally_p &= ~SALLY_FLAG.N; + } + + if (~(sally_a ^ data) & ((ah << 4) ^ sally_a) & 128) { + sally_p |= SALLY_FLAG.V; + } + else { + sally_p &= ~SALLY_FLAG.V; + } + + if (ah > 9) { + ah += 6; + } + + if (ah > 15) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + sally_a = (ah << 4) | (al & 15); + } + else { + pair temp; + temp.w = sally_a + data + (sally_p & SALLY_FLAG.C); + + if (temp.b.h) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + if (~(sally_a ^ data) & (sally_a ^ temp.b.l) & 128) { + sally_p |= SALLY_FLAG.V; + } + else { + sally_p &= ~SALLY_FLAG.V; + } + + sally_Flags(temp.b.l); + sally_a = temp.b.l; + } +} + +static void sally_AND(void) { + sally_a &= memory_Read(sally_address.w); + sally_Flags(sally_a); +} + +static void sally_ASLA(void) { + if(sally_a & 128) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + sally_a <<= 1; + sally_Flags(sally_a); +} + +static void sally_ASL(void) { + uint8_t data = memory_Read(sally_address.w); + + if (data & 128) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + data <<= 1; + memory_Write(sally_address.w, data); + sally_Flags(data); +} + +static void sally_BCC(void) { + sally_Branch(!(sally_p & SALLY_FLAG.C)); +} + +static void sally_BCS(void) { + sally_Branch(sally_p & SALLY_FLAG.C); +} + +static void sally_BEQ(void) { + sally_Branch(sally_p & SALLY_FLAG.Z); +} + +static void sally_BIT(void) { + uint8_t data = memory_Read(sally_address.w); + + if (!(data & sally_a)) { + sally_p |= SALLY_FLAG.Z; + } + else { + sally_p &= ~SALLY_FLAG.Z; + } + + sally_p &= ~SALLY_FLAG.V; + sally_p &= ~SALLY_FLAG.N; + sally_p |= data & 64; + sally_p |= data & 128; +} + +static void sally_BMI(void) { + sally_Branch(sally_p & SALLY_FLAG.N); +} + +static void sally_BNE(void) { + sally_Branch(!(sally_p & SALLY_FLAG.Z)); +} + +static void sally_BPL(void) { + sally_Branch(!(sally_p & SALLY_FLAG.N)); +} + +static void sally_BRK(void) { + sally_pc.w++; + sally_p |= SALLY_FLAG.B; + + sally_Push(sally_pc.b.h); + sally_Push(sally_pc.b.l); + sally_Push(sally_p); + + sally_p |= SALLY_FLAG.I; + sally_pc.b.l = memory_ram[SALLY_IRQ.L]; + sally_pc.b.h = memory_ram[SALLY_IRQ.H]; +} + +static void sally_BVC(void) { + sally_Branch(!(sally_p & SALLY_FLAG.V)); +} + +static void sally_BVS(void) { + sally_Branch(sally_p & SALLY_FLAG.V); +} + +static void sally_CLC(void) { + sally_p &= ~SALLY_FLAG.C; +} + +static void sally_CLD(void) { + sally_p &= ~SALLY_FLAG.D; +} + +static void sally_CLI(void) { + sally_p &= ~SALLY_FLAG.I; +} + +static void sally_CLV(void) { + sally_p &= ~SALLY_FLAG.V; +} + +static void sally_CMP(void) { + uint8_t data = memory_Read(sally_address.w); + + if (sally_a >= data) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + sally_Flags(sally_a - data); +} + +static void sally_CPX(void) { + uint8_t data = memory_Read(sally_address.w); + + if (sally_x >= data) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + sally_Flags(sally_x - data); +} + +static void sally_CPY(void) { + uint8_t data = memory_Read(sally_address.w); + + if (sally_y >= data) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + sally_Flags(sally_y - data); +} + +static void sally_DEC(void) { + uint8_t data = memory_Read(sally_address.w); + memory_Write(sally_address.w, --data); + sally_Flags(data); +} + +static void sally_DEX(void) { + sally_Flags(--sally_x); +} + +static void sally_DEY(void) { + sally_Flags(--sally_y); +} + +static void sally_EOR(void) { + sally_a ^= memory_Read(sally_address.w); + sally_Flags(sally_a); +} + +static void sally_INC(void) { + uint8_t data = memory_Read(sally_address.w); + memory_Write(sally_address.w, ++data); + sally_Flags(data); +} + +static void sally_INX(void) { + sally_Flags(++sally_x); +} + +static void sally_INY(void) { + sally_Flags(++sally_y); +} + +static void sally_JMP(void) { + sally_pc = sally_address; +} + +static void sally_JSR(void) { + sally_pc.w--; + sally_Push(sally_pc.b.h); + sally_Push(sally_pc.b.l); + + sally_pc = sally_address; +} + +static void sally_LDA(void) { + sally_a = memory_Read(sally_address.w); + sally_Flags(sally_a); +} + +static void sally_LDX(void) { + sally_x = memory_Read(sally_address.w); + sally_Flags(sally_x); +} + +static void sally_LDY(void) { + sally_y = memory_Read(sally_address.w); + sally_Flags(sally_y); +} + +static void sally_LSRA(void) { + sally_p &= ~SALLY_FLAG.C; + sally_p |= sally_a & 1; + + sally_a >>= 1; + sally_Flags(sally_a); +} + +static void sally_LSR(void) { + uint8_t data = memory_Read(sally_address.w); + + sally_p &= ~SALLY_FLAG.C; + sally_p |= data & 1; + + data >>= 1; + memory_Write(sally_address.w, data); + sally_Flags(data); +} + +static void sally_NOP(void) { +} + +static void sally_ORA(void) { + sally_a |= memory_Read(sally_address.w); + sally_Flags(sally_a); +} + +static void sally_PHA(void) { + sally_Push(sally_a); +} + +static void sally_PHP(void) { + sally_Push(sally_p); +} + +static void sally_PLA(void) { + sally_a = sally_Pop(); + sally_Flags(sally_a); +} + +static void sally_PLP(void) { + sally_p = sally_Pop(); +} + +static void sally_ROLA(void) { + uint8_t temp = sally_p; + + if (sally_a & 128) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + sally_a <<= 1; + sally_a |= temp & SALLY_FLAG.C; + sally_Flags(sally_a); +} + +static void sally_ROL(void) { + uint8_t data = memory_Read(sally_address.w); + uint8_t temp = sally_p; + + if (data & 128) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + data <<= 1; + data |= temp & 1; + memory_Write(sally_address.w, data); + sally_Flags(data); +} + +static void sally_RORA(void) { + uint8_t temp = sally_p; + + sally_p &= ~SALLY_FLAG.C; + sally_p |= sally_a & 1; + + sally_a >>= 1; + if(temp & SALLY_FLAG.C) { + sally_a |= 128; + } + + sally_Flags(sally_a); +} + +static void sally_ROR(void) { + uint8_t data = memory_Read(sally_address.w); + uint8_t temp = sally_p; + + sally_p &= ~SALLY_FLAG.C; + sally_p |= data & 1; + + data >>= 1; + if(temp & 1) { + data |= 128; + } + + memory_Write(sally_address.w, data); + sally_Flags(data); +} + +static void sally_RTI(void) { + sally_p = sally_Pop(); + sally_pc.b.l = sally_Pop(); + sally_pc.b.h = sally_Pop(); +} + +static void sally_RTS(void) { + sally_pc.b.l = sally_Pop(); + sally_pc.b.h = sally_Pop(); + sally_pc.w++; +} + +static void sally_SBC(void) { + uint8_t data = memory_Read(sally_address.w); + + if (sally_p & SALLY_FLAG.D) { + uint16_t al = (sally_a & 15) - (data & 15) - !(sally_p & SALLY_FLAG.C); + uint16_t ah = (sally_a >> 4) - (data >> 4); + + if(al > 9) { + al -= 6; + ah--; + } + + if(ah > 9) { + ah -= 6; + } + + pair temp; + temp.w = sally_a - data - !(sally_p & SALLY_FLAG.C); + + if (!temp.b.h) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + if ((sally_a ^ data) & (sally_a ^ temp.b.l) & 128) { + sally_p |= SALLY_FLAG.V; + } + else { + sally_p &= ~SALLY_FLAG.V; + } + + sally_Flags(temp.b.l); + sally_a = (ah << 4) | (al & 15); + } + else { + pair temp; + temp.w = sally_a - data - !(sally_p & SALLY_FLAG.C); + + if (!temp.b.h) { + sally_p |= SALLY_FLAG.C; + } + else { + sally_p &= ~SALLY_FLAG.C; + } + + if ((sally_a ^ data) & (sally_a ^ temp.b.l) & 128) { + sally_p |= SALLY_FLAG.V; + } + else { + sally_p &= ~SALLY_FLAG.V; + } + + sally_Flags(temp.b.l); + sally_a = temp.b.l; + } +} + +static void sally_SEC(void) { + sally_p |= SALLY_FLAG.C; +} + +static void sally_SED(void) { + sally_p |= SALLY_FLAG.D; +} + +static void sally_SEI(void) { + sally_p |= SALLY_FLAG.I; +} + +static void sally_STA(void) { + memory_Write(sally_address.w, sally_a); +} + +static void sally_stx(void) { + memory_Write(sally_address.w, sally_x); +} + +static void sally_STY(void) { + memory_Write(sally_address.w, sally_y); +} + +static void sally_TAX(void) { + sally_x = sally_a; + sally_Flags(sally_x); +} + +static void sally_TAY(void) { + sally_y = sally_a; + sally_Flags(sally_y); +} + +static void sally_TSX(void) { + sally_x = sally_s; + sally_Flags(sally_x); +} + +static void sally_TXA(void) { + sally_a = sally_x; + sally_Flags(sally_a); +} + +static void sally_TXS(void) { + sally_s = sally_x; +} + +static void sally_TYA(void) { + sally_a = sally_y; + sally_Flags(sally_a); +} + +void sally_Reset(void) { + sally_a = 0; + sally_x = 0; + sally_y = 0; + sally_p = SALLY_FLAG.R; + sally_s = 0; + sally_pc.w = 0; +} + +uint32_t sally_ExecuteInstruction(void) { + // Reset half cycle flag + half_cycle = false; + + sally_opcode = memory_Read(sally_pc.w++); + sally_cycles = SALLY_CYCLES[sally_opcode]; + + switch (sally_opcode) { + case 0x00: + sally_BRK(); + break; + + case 0x01: + sally_IndirectX(); + sally_ORA(); + break; + + case 0x05: + sally_ZeroPage(); + sally_ORA(); + break; + + case 0x06: + sally_ZeroPage(); + sally_ASL(); + break; + + case 0x08: + sally_PHP(); + break; + + case 0x09: + sally_Immediate(); + sally_ORA(); + break; + + case 0x0a: + sally_ASLA(); + break; + + case 0x0b: // ANC + case 0x2b: { // ANC + sally_Immediate(); + sally_AND(); + if (sally_a & 128) { + sally_p |= SALLY_FLAG.C; + } + else { + //sally_p &= ~SALLY_FLAG.C; + sally_p = (sally_p & ~SALLY_FLAG.C) & 0xFF; + } + break; + } + case 0x0d: + sally_Absolute(); + sally_ORA(); + break; + + case 0x0e: + sally_Absolute(); + sally_ASL(); + break; + + case 0x10: + sally_Relative(); + sally_BPL(); + break; + + case 0x11: + sally_IndirectY(); + sally_ORA(); + sally_Delay(sally_y); + break; + + case 0x15: + sally_ZeroPageX(); + sally_ORA(); + break; + + case 0x16: + sally_ZeroPageX(); + sally_ASL(); + break; + + case 0x18: + sally_CLC(); + break; + + case 0x19: + sally_AbsoluteY(); + sally_ORA(); + sally_Delay(sally_y); + break; + + case 0x1d: + sally_AbsoluteX(); + sally_ORA(); + sally_Delay(sally_x); + break; + + case 0x1e: + sally_AbsoluteX(); + sally_ASL(); + break; + + case 0x20: + sally_Absolute(); + sally_JSR(); + break; + + case 0x21: + sally_IndirectX(); + sally_AND(); + break; + + case 0x24: + sally_ZeroPage(); + sally_BIT(); + // Add a half cycle if RIOT/TIA location is accessed. We only track + // INPT4 since it is the only one that is accessed during the + // lightgun hit detection loop. This should be extended to take into + // consideration all RIOT and TIA accesses. + if (sally_address.w == INPT4) { + half_cycle = true; + } + break; + + case 0x25: + sally_ZeroPage(); + sally_AND(); + break; + + case 0x26: + sally_ZeroPage(); + sally_ROL(); + break; + + case 0x28: + sally_PLP(); + break; + + case 0x29: + sally_Immediate(); + sally_AND(); + break; + + case 0x2a: + sally_ROLA(); + break; + + case 0x2c: + sally_Absolute(); + sally_BIT(); + break; + + case 0x2d: + sally_Absolute(); + sally_AND(); + break; + + case 0x2e: + sally_Absolute(); + sally_ROL(); + break; + + case 0x30: + sally_Relative(); + sally_BMI(); + break; + + case 0x31: + sally_IndirectY(); + sally_AND(); + sally_Delay(sally_y); + break; + + case 0x35: + sally_ZeroPageX(); + sally_AND(); + break; + + case 0x36: + sally_ZeroPageX(); + sally_ROL(); + break; + + case 0x38: + sally_SEC(); + break; + + case 0x39: + sally_AbsoluteY(); + sally_AND(); + sally_Delay(sally_y); + break; + + case 0x3d: + sally_AbsoluteX(); + sally_AND(); + sally_Delay(sally_x); + break; + + case 0x3e: + sally_AbsoluteX(); + sally_ROL(); + break; + + case 0x40: + sally_RTI(); + break; + + case 0x41: + sally_IndirectX(); + sally_EOR(); + break; + + case 0x45: + sally_ZeroPage(); + sally_EOR(); + break; + + case 0x46: + sally_ZeroPage(); + sally_LSR(); + break; + + case 0x48: + sally_PHA(); + break; + + case 0x49: + sally_Immediate(); + sally_EOR(); + break; + + case 0x4a: + sally_LSRA(); + break; + + case 0x4b: // ALR (ASR) + sally_Immediate(); + sally_AND(); + sally_LSRA(); + break; + + case 0x4c: + sally_Absolute(); + sally_JMP(); + break; + + case 0x4d: + sally_Absolute(); + sally_EOR(); + break; + + case 0x4e: + sally_Absolute(); + sally_LSR(); + break; + + case 0x50: + sally_Relative(); + sally_BVC(); + break; + + case 0x51: + sally_IndirectY(); + sally_EOR(); + sally_Delay(sally_y); + break; + + case 0x55: + sally_ZeroPageX(); + sally_EOR(); + break; + + case 0x56: + sally_ZeroPageX(); + sally_LSR(); + break; + + case 0x58: + sally_CLI(); + break; + + case 0x59: + sally_AbsoluteY(); + sally_EOR(); + sally_Delay(sally_y); + break; + + case 0x5d: + sally_AbsoluteX(); + sally_EOR(); + sally_Delay(sally_x); + break; + + case 0x5e: + sally_AbsoluteX(); + sally_LSR(); + break; + + case 0x60: + sally_RTS(); + break; + + case 0x61: + sally_IndirectX(); + sally_ADC(); + break; + + case 0x65: + sally_ZeroPage(); + sally_ADC(); + break; + + case 0x66: + sally_ZeroPage(); + sally_ROR(); + break; + + case 0x68: + sally_PLA(); + break; + + case 0x69: + sally_Immediate(); + sally_ADC(); + break; + + case 0x6a: + sally_RORA(); + break; + + case 0x6c: + sally_Indirect(); + sally_JMP(); + break; + + case 0x6d: + sally_Absolute(); + sally_ADC(); + break; + + case 0x6e: + sally_Absolute(); + sally_ROR(); + break; + + case 0x70: + sally_Relative(); + sally_BVS(); + break; + + case 0x71: + sally_IndirectY(); + sally_ADC(); + sally_Delay(sally_y); + break; + + case 0x75: + sally_ZeroPageX(); + sally_ADC(); + break; + + case 0x76: + sally_ZeroPageX(); + sally_ROR(); + break; + + case 0x78: + sally_SEI(); + break; + + case 0x79: + sally_AbsoluteY(); + sally_ADC(); + sally_Delay(sally_y); + break; + + case 0x7d: + sally_AbsoluteX(); + sally_ADC(); + sally_Delay(sally_x); + break; + + case 0x7e: + sally_AbsoluteX(); + sally_ROR(); + break; + + case 0x81: + sally_IndirectX(); + sally_STA(); + break; + + case 0x84: + sally_ZeroPage(); + sally_STY(); + break; + + case 0x85: + sally_ZeroPage(); + sally_STA(); + break; + + case 0x86: + sally_ZeroPage(); + sally_stx(); + break; + + case 0x88: + sally_DEY(); + break; + + case 0x8a: + sally_TXA(); + break; + + case 0x8c: + sally_Absolute(); + sally_STY(); + break; + + case 0x8d: + sally_Absolute(); + sally_STA(); + break; + + case 0x8e: + sally_Absolute(); + sally_stx(); + break; + + case 0x90: + sally_Relative(); + sally_BCC(); + break; + + case 0x91: + sally_IndirectY(); + sally_STA(); + break; + + case 0x94: + sally_ZeroPageX(); + sally_STY(); + break; + + case 0x95: + sally_ZeroPageX(); + sally_STA(); + break; + + case 0x96: + sally_ZeroPageY(); + sally_stx(); + break; + + case 0x98: + sally_TYA(); + break; + + case 0x99: + sally_AbsoluteY(); + sally_STA(); + break; + + case 0x9a: + sally_TXS(); + break; + + case 0x9d: + sally_AbsoluteX(); + sally_STA(); + break; + + case 0xa0: + sally_Immediate(); + sally_LDY(); + break; + + case 0xa1: + sally_IndirectX(); + sally_LDA(); + break; + + case 0xa2: + sally_Immediate(); + sally_LDX(); + break; + + case 0xa4: + sally_ZeroPage(); + sally_LDY(); + break; + + case 0xa5: + sally_ZeroPage(); + sally_LDA(); + break; + + case 0xa6: + sally_ZeroPage(); + sally_LDX(); + break; + + case 0xa8: + sally_TAY(); + break; + + case 0xa9: + sally_Immediate(); + sally_LDA(); + break; + + case 0xaa: + sally_TAX(); + break; + + case 0xac: + sally_Absolute(); + sally_LDY(); + break; + + case 0xad: + sally_Absolute(); + sally_LDA(); + break; + + case 0xae: + sally_Absolute(); + sally_LDX(); + break; + + case 0xb0: + sally_Relative(); + sally_BCS(); + break; + + case 0xb1: + sally_IndirectY(); + sally_LDA(); + sally_Delay(sally_y); + break; + + case 0xb4: + sally_ZeroPageX(); + sally_LDY(); + break; + + case 0xb5: + sally_ZeroPageX(); + sally_LDA(); + break; + + case 0xb6: + sally_ZeroPageY(); + sally_LDX(); + break; + + case 0xb8: + sally_CLV(); + break; + + case 0xb9: + sally_AbsoluteY(); + sally_LDA(); + sally_Delay(sally_y); + break; + + case 0xba: + sally_TSX(); + break; + + case 0xbc: + sally_AbsoluteX(); + sally_LDY(); + sally_Delay(sally_x); + break; + + case 0xbd: + sally_AbsoluteX(); + sally_LDA(); + sally_Delay(sally_x); + break; + + case 0xbe: + sally_AbsoluteY(); + sally_LDX(); + sally_Delay(sally_y); + break; + + case 0xc0: + sally_Immediate(); + sally_CPY(); + break; + + case 0xc1: + sally_IndirectX(); + sally_CMP(); + break; + + case 0xc4: + sally_ZeroPage(); + sally_CPY(); + break; + + case 0xc5: + sally_ZeroPage(); + sally_CMP(); + break; + + case 0xc6: + sally_ZeroPage(); + sally_DEC(); + break; + + case 0xc8: + sally_INY(); + break; + + case 0xc9: + sally_Immediate(); + sally_CMP(); + break; + + case 0xca: + sally_DEX(); + break; + + case 0xcc: + sally_Absolute(); + sally_CPY(); + break; + + case 0xcd: + sally_Absolute(); + sally_CMP(); + break; + + case 0xce: + sally_Absolute(); + sally_DEC(); + break; + + case 0xd0: + sally_Relative(); + sally_BNE(); + break; + + case 0xd1: + sally_IndirectY(); + sally_CMP(); + sally_Delay(sally_y); + break; + + case 0xd5: + sally_ZeroPageX(); + sally_CMP(); + break; + + case 0xd6: + sally_ZeroPageX(); + sally_DEC(); + break; + + case 0xd8: + sally_CLD(); + break; + + case 0xd9: + sally_AbsoluteY(); + sally_CMP(); + sally_Delay(sally_y); + break; + + case 0xdd: + sally_AbsoluteX(); + sally_CMP(); + sally_Delay(sally_x); + break; + + case 0xde: + sally_AbsoluteX(); + sally_DEC(); + break; + + case 0xe0: + sally_Immediate(); + sally_CPX(); + break; + + case 0xe1: + sally_IndirectX(); + sally_SBC(); + break; + + case 0xe4: + sally_ZeroPage(); + sally_CPX(); + break; + + case 0xe5: + sally_ZeroPage(); + sally_SBC(); + break; + + case 0xe6: + sally_ZeroPage(); + sally_INC(); + break; + + case 0xe8: + sally_INX(); + break; + + case 0xe9: + sally_Immediate(); + sally_SBC(); + break; + + case 0xea: + sally_NOP(); + break; + + case 0xec: + sally_Absolute(); + sally_CPX(); + break; + + case 0xed: + sally_Absolute(); + sally_SBC(); + break; + + case 0xee: + sally_Absolute(); + sally_INC(); + break; + + case 0xf0: + sally_Relative(); + sally_BEQ(); + break; + + case 0xf1: + sally_IndirectY(); + sally_SBC(); + sally_Delay(sally_y); + break; + + case 0xf5: + sally_ZeroPageX(); + sally_SBC(); + break; + + case 0xf6: + sally_ZeroPageX(); + sally_INC(); + break; + + case 0xf8: + sally_SED(); + break; + + case 0xf9: + sally_AbsoluteY(); + sally_SBC(); + sally_Delay(sally_y); + break; + + case 0xfd: + sally_AbsoluteX(); + sally_SBC(); + sally_Delay(sally_x); + break; + + case 0xfe: + sally_AbsoluteX(); + sally_INC(); + break; + + default: + break; + } + + return sally_cycles; +} + +uint32_t sally_ExecuteRES(void) { + sally_p = SALLY_FLAG.I | SALLY_FLAG.R | SALLY_FLAG.Z; + sally_pc.b.l = memory_ram[SALLY_RES.L]; + sally_pc.b.h = memory_ram[SALLY_RES.H]; + return 6; +} + +uint32_t sally_ExecuteNMI(void) { + sally_Push(sally_pc.b.h); + sally_Push(sally_pc.b.l); + sally_p &= ~SALLY_FLAG.B; + sally_Push(sally_p); + sally_p |= SALLY_FLAG.I; + sally_pc.b.l = memory_ram[SALLY_NMI.L]; + sally_pc.b.h = memory_ram[SALLY_NMI.H]; + return 7; +} + +uint32_t sally_ExecuteIRQ(void) { + if (!(sally_p & SALLY_FLAG.I)) { + sally_Push(sally_pc.b.h); + sally_Push(sally_pc.b.l); + sally_p &= ~SALLY_FLAG.B; + sally_Push(sally_p); + sally_p |= SALLY_FLAG.I; + sally_pc.b.l = memory_ram[SALLY_IRQ.L]; + sally_pc.b.h = memory_ram[SALLY_IRQ.H]; + } + return 7; +} diff --git a/core/Sally.h b/src/Sally.h old mode 100755 new mode 100644 similarity index 65% rename from core/Sally.h rename to src/Sally.h index 5e897a2..df70be8 --- a/core/Sally.h +++ b/src/Sally.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -28,20 +29,16 @@ #include "Memory.h" #include "Pair.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern void sally_Reset( ); -extern uint sally_ExecuteInstruction( ); -extern uint sally_ExecuteRES( ); -extern uint sally_ExecuteNMI( ); -extern uint sally_ExecuteIRQ( ); -extern byte sally_a; -extern byte sally_x; -extern byte sally_y; -extern byte sally_p; -extern byte sally_s; +extern void sally_Reset(void); +extern uint32_t sally_ExecuteInstruction(void); +extern uint32_t sally_ExecuteRES(void); +extern uint32_t sally_ExecuteNMI(void); +extern uint32_t sally_ExecuteIRQ(void); +extern uint8_t sally_a; +extern uint8_t sally_x; +extern uint8_t sally_y; +extern uint8_t sally_p; +extern uint8_t sally_s; extern pair sally_pc; -#endif \ No newline at end of file +#endif diff --git a/core/Sound.cpp b/src/Sound.c old mode 100755 new mode 100644 similarity index 89% rename from core/Sound.cpp rename to src/Sound.c index 9b67f7b..9e151cc --- a/core/Sound.cpp +++ b/src/Sound.c @@ -38,14 +38,14 @@ static void sound_Resample(const uint8_t *source, uint8_t *target, int length) { int sourceIndex = 0; int targetIndex = 0; int max = ((prosystem_frequency * prosystem_scanlines) << 1); - + while (targetIndex < length) { if (measurement >= max) { target[targetIndex++] = source[sourceIndex]; measurement -= max; } else { - sourceIndex++; + ++sourceIndex; measurement += nSamplesPerSec; } } @@ -56,25 +56,25 @@ uint32_t sound_Store(uint8_t *out_buffer) { uint32_t length = nSamplesPerSec / prosystem_frequency; sound_Resample(tia_buffer, out_buffer, length); tia_Clear(); - + // Ballblazer, Commando, various homebrew and hacks if(cartridge_pokey || xm_pokey_enabled) { uint8_t pokeySample[MAX_BUFFER_SIZE]; memset(pokeySample, 0, MAX_BUFFER_SIZE); sound_Resample(pokey_buffer, pokeySample, length); - - for(uint32_t index = 0; index < length; index++) { + + for(uint32_t index = 0; index < length; ++index) { uint32_t sound = out_buffer[index] + pokeySample[index]; out_buffer[index] = sound >> 1; } } else { - for(uint32_t index = 0; index < length; index++) { - out_buffer[index] = out_buffer[index] * 0.75; //>> 1; - } + for(uint32_t index = 0; index < length; ++index) { + out_buffer[index] = out_buffer[index] * 0.75; //>> 1; + } } pokey_Clear(); - + return length; } diff --git a/core/Sound.h b/src/Sound.h old mode 100755 new mode 100644 similarity index 72% rename from core/Sound.h rename to src/Sound.h index 10424a0..73d450f --- a/core/Sound.h +++ b/src/Sound.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -28,13 +29,10 @@ #include "ProSystem.h" #include "Tia.h" #include "Pokey.h" +#include "Cartridge.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; - -extern uint sound_Store(byte *out_buffer); -extern void sound_SetSampleRate(uint rate); -extern uint sound_GetSampleRate(); +extern uint32_t sound_Store(uint8_t *out_buffer); +extern void sound_SetSampleRate(uint32_t rate); +extern uint32_t sound_GetSampleRate(void); #endif diff --git a/src/Tia.c b/src/Tia.c new file mode 100644 index 0000000..8ec8ea1 --- /dev/null +++ b/src/Tia.c @@ -0,0 +1,212 @@ +// ---------------------------------------------------------------------------- +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ +// +// ---------------------------------------------------------------------------- +// Copyright 2005 Greg Stanton +// Copyright 2020 Rupert Carmichael +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// ---------------------------------------------------------------------------- +// TiaSound is Copyright(c) 1997 by Ron Fries +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of version 2 of the GNU Library General Public License +// as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library +// General Public License for more details. +// To obtain a copy of the GNU Library General Public License, write to the +// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// Any permitted reproduction of these routines, in whole or in part, must +// bear this legend. +// ---------------------------------------------------------------------------- +// Tia.c +// ---------------------------------------------------------------------------- +#include +#include + +#include "Tia.h" +#define TIA_POLY4_SIZE 15 +#define TIA_POLY5_SIZE 31 +#define TIA_POLY9_SIZE 511 + +uint8_t tia_buffer[TIA_BUFFER_SIZE] = {0}; +uint32_t tia_size = TIA_BUFFER_SIZE; // previously was 524 + +static const uint8_t TIA_POLY4[] = {1,1,0,1,1,1,0,0,0,0,1,0,1,0,0}; +static const uint8_t TIA_POLY5[] = {0,0,1,0,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0,1,1,1,0,1,0,1,0,0,0,0,1}; +static const uint8_t TIA_POLY9[] = {0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,1,1,0,0,1,0,1,0,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,0,1,1,1,0,1,1,0,0,1,0,0,1,1,1,1,0,1,0,0,0,0,1,1,0,1,1,0,0,0,1,0,0,0,1,1,1,1,0,1,0,1,1,0,1,0,1,0,0,0,0,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,1,1,0,0,1,1,0,1,1,0,0,1,1,1,1,1,0,0,1,1,0,0,0,1,1,0,1,0,0,0,1,1,0,0,1,1,1,1,0,0,1,0,0,0,1,1,1,0,0,1,1,0,1,0,1,1,0,1,1,0,1,0,0,1,0,0,1,1,1,1,1,1,0,1,1,1,1,0,1,1,0,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,1,0,1,1,0,0,0,0,1,0,1,1,1,1,0,1,0,0,0,1,1,0,0,0,1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,0,0,1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,1,1,1,0,0,0,1,1,1,0,0,0,1,0,0,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,0,1,0,1,1,1,1,0,0,1,0,1,0,1,1,1,0,0,0,0,0,1,1,0,1,1,0,0,0,1,0,1,0,1,0,0,0,0,1,0,1,1,1,0,0,0,0,1,0,0,1,0,1,0,0,0,1,0,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,1,0,0,1,1,0,1,0,0,1,0,0,0,1,0,0,1,0,1,0,0,0,1,1,0,1,0,0,0,0,0,1,1,1,1,0,0,1,0,0,1,0,1,1,1,1,1,1,1,0,1,0,0,1,0,0,0,1,1,0,1,1,1,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,1,1,0,0,1,0,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0}; +static const uint8_t TIA_DIV31[] = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0}; +static uint8_t tia_volume[2] = {0}; +static uint8_t tia_counterMax[2] = {0}; +static uint8_t tia_counter[2] = {0}; +static uint8_t tia_audc[2] = {0}; +static uint8_t tia_audf[2] = {0}; +static uint8_t tia_audv[2] = {0}; +static uint32_t tia_poly4Cntr[2] = {0}; +static uint32_t tia_poly5Cntr[2] = {0}; +static uint32_t tia_poly9Cntr[2] = {0}; +static uint32_t tia_soundCntr = 0; + +static void tia_ProcessChannel(uint8_t channel) { + tia_poly5Cntr[channel]++; + + if (tia_poly5Cntr[channel] == TIA_POLY5_SIZE) { + tia_poly5Cntr[channel] = 0; + } + + if (((tia_audc[channel] & 2) == 0) || (((tia_audc[channel] & 1) == 0) && TIA_DIV31[tia_poly5Cntr[channel]]) || (((tia_audc[channel] & 1) == 1) && TIA_POLY5[tia_poly5Cntr[channel]])) { + if(tia_audc[channel] & 4) { + tia_volume[channel] = (!tia_volume[channel])? tia_audv[channel]: 0; + } + else if (tia_audc[channel] & 8) { + if (tia_audc[channel] == 8) { + tia_poly9Cntr[channel]++; + + if (tia_poly9Cntr[channel] == TIA_POLY9_SIZE) { + tia_poly9Cntr[channel] = 0; + } + + tia_volume[channel] = (TIA_POLY9[tia_poly9Cntr[channel]])? tia_audv[channel]: 0; + } + else { + tia_volume[channel] = (TIA_POLY5[tia_poly5Cntr[channel]])? tia_audv[channel]: 0; + } + } + else { + tia_poly4Cntr[channel]++; + + if (tia_poly4Cntr[channel] == TIA_POLY4_SIZE) { + tia_poly4Cntr[channel] = 0; + } + + tia_volume[channel] = (TIA_POLY4[tia_poly4Cntr[channel]])? tia_audv[channel]: 0; + } + } +} + +void tia_Reset(void) { + tia_soundCntr = 0; + + for (int index = 0; index < 2; index++) { + tia_volume[index] = 0; + tia_counterMax[index] = 0; + tia_counter[index] = 0; + tia_audc[index] = 0; + tia_audf[index] = 0; + tia_audv[index] = 0; + tia_poly4Cntr[index] = 0; + tia_poly5Cntr[index] = 0; + tia_poly9Cntr[index] = 0; + } + + tia_Clear(); +} + +void tia_Clear(void) { + for (int index = 0; index < TIA_BUFFER_SIZE; index++) { + tia_buffer[index] = 0; + } +} + +void tia_SetRegister(uint16_t address, uint8_t data) { + uint8_t channel; + uint8_t frequency; + + switch (address) { + case AUDC0: + tia_audc[0] = data & 15; + channel = 0; + break; + + case AUDC1: + tia_audc[1] = data & 15; + channel = 1; + break; + + case AUDF0: + tia_audf[0] = data & 31; + channel = 0; + break; + + case AUDF1: + tia_audf[1] = data & 31; + channel = 1; + break; + + case AUDV0: + tia_audv[0] = (data & 15) << 2; + channel = 0; + break; + + case AUDV1: + tia_audv[1] = (data & 15) << 2; + channel = 1; + break; + + default: + return; + } + + if (tia_audc[channel] == 0) { + frequency = 0; + tia_volume[channel] = tia_audv[channel]; + } + else { + frequency = tia_audf[channel] + 1; + if(tia_audc[channel] > 11) { + frequency *= 3; + } + } + + if (frequency != tia_counterMax[channel]) { + tia_counterMax[channel] = frequency; + + if (tia_counter[channel] == 0 || frequency == 0) { + tia_counter[channel] = frequency; + } + } +} + +void tia_Process(uint32_t length) { + for(size_t index = 0; index < length; index++) { + if (tia_counter[0] > 1) { + tia_counter[0]--; + } + else if (tia_counter[0] == 1) { + tia_counter[0] = tia_counterMax[0]; + tia_ProcessChannel(0); + } + + if (tia_counter[1] > 1) { + tia_counter[1]--; + } + else if (tia_counter[1] == 1) { + tia_counter[1] = tia_counterMax[1]; + tia_ProcessChannel(1); + } + + tia_buffer[tia_soundCntr++] = tia_volume[0] + tia_volume[1]; + + if (tia_soundCntr >= tia_size) { + tia_soundCntr = 0; + } + } +} diff --git a/core/Tia.h b/src/Tia.h old mode 100755 new mode 100644 similarity index 57% rename from core/Tia.h rename to src/Tia.h index 7e96943..77e79ac --- a/core/Tia.h +++ b/src/Tia.h @@ -1,11 +1,12 @@ // ---------------------------------------------------------------------------- -// ___ ___ ___ ___ ___ ____ ___ _ _ -// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / -// / / \ /__/ ___/ ___/ ___/ / /__ / / emulator +// ___ ___ ___ ___ ___ ____ ___ _ _ __ ___ +// /__/ /__/ / / /__ /__/ /__ / /_ / |/ / / / _ +// / / \ /__/ ___/ ___/ ___/ / /__ / / ___/ /__/ // // ---------------------------------------------------------------------------- // Copyright 2005 Greg Stanton -// +// Copyright 2020 Rupert Carmichael +// // 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 @@ -20,21 +21,21 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // ---------------------------------------------------------------------------- -// TiaSound is Copyright(c) 1997 by Ron Fries -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of version 2 of the GNU Library General Public License -// as published by the Free Software Foundation. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library -// General Public License for more details. -// To obtain a copy of the GNU Library General Public License, write to the -// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// -// Any permitted reproduction of these routines, in whole or in part, must -// bear this legend. +// TiaSound is Copyright(c) 1997 by Ron Fries +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of version 2 of the GNU Library General Public License +// as published by the Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library +// General Public License for more details. +// To obtain a copy of the GNU Library General Public License, write to the +// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// Any permitted reproduction of these routines, in whole or in part, must +// bear this legend. // ---------------------------------------------------------------------------- // Tia.h // ---------------------------------------------------------------------------- @@ -44,15 +45,11 @@ #include "Equates.h" -typedef unsigned char byte; -typedef unsigned short word; -typedef unsigned int uint; +extern void tia_Reset(void); +extern void tia_SetRegister(uint16_t address, uint8_t data); +extern void tia_Clear(void); +extern void tia_Process(uint32_t length); +extern uint8_t tia_buffer[TIA_BUFFER_SIZE]; +extern uint32_t tia_size; -extern void tia_Reset( ); -extern void tia_SetRegister(word address, byte data); -extern void tia_Clear( ); -extern void tia_Process(uint length); -extern byte tia_buffer[TIA_BUFFER_SIZE]; -extern uint tia_size; - -#endif \ No newline at end of file +#endif diff --git a/src/md5.c b/src/md5.c new file mode 100644 index 0000000..b235e17 --- /dev/null +++ b/src/md5.c @@ -0,0 +1,291 @@ +/* + * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. + * MD5 Message-Digest Algorithm (RFC 1321). + * + * Homepage: + * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 + * + * Author: + * Alexander Peslyak, better known as Solar Designer + * + * This software was written by Alexander Peslyak in 2001. No copyright is + * claimed, and the software is hereby placed in the public domain. + * In case this attempt to disclaim copyright and place the software in the + * public domain is deemed null and void, then the software is + * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the + * general public under the following terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + * + * (This is a heavily cut-down "BSD license".) + * + * This differs from Colin Plumb's older public domain implementation in that + * no exactly 32-bit integer data type is required (any 32-bit or wider + * unsigned integer data type will do), there's no compile-time endianness + * configuration, and the function prototypes match OpenSSL's. No code from + * Colin Plumb's implementation has been reused; this comment merely compares + * the properties of the two independent implementations. + * + * The primary goals of this implementation are portability and ease of use. + * It is meant to be fast, but not as fast as possible. Some known + * optimizations are not included to reduce source code size and avoid + * compile-time configuration. + */ + +#ifndef HAVE_OPENSSL + +#include + +#include "md5.h" + +/* + * The basic MD5 functions. + * + * F and G are optimized compared to their RFC 1321 definitions for + * architectures that lack an AND-NOT instruction, just like in Colin Plumb's + * implementation. + */ +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) +#define H(x, y, z) (((x) ^ (y)) ^ (z)) +#define H2(x, y, z) ((x) ^ ((y) ^ (z))) +#define I(x, y, z) ((y) ^ ((x) | ~(z))) + +/* + * The MD5 transformation for all four rounds. + */ +#define STEP(f, a, b, c, d, x, t, s) \ + (a) += f((b), (c), (d)) + (x) + (t); \ + (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ + (a) += (b); + +/* + * SET reads 4 input bytes in little-endian byte order and stores them in a + * properly aligned word in host byte order. + * + * The check for little-endian architectures that tolerate unaligned memory + * accesses is just an optimization. Nothing will break if it fails to detect + * a suitable architecture. + * + * Unfortunately, this optimization may be a C strict aliasing rules violation + * if the caller's data buffer has effective type that cannot be aliased by + * MD5_u32plus. In practice, this problem may occur if these MD5 routines are + * inlined into a calling function, or with future and dangerously advanced + * link-time optimizations. For the time being, keeping these MD5 routines in + * their own translation unit avoids the problem. + */ +#if defined(__i386__) || defined(__x86_64__) || defined(__vax__) +#define SET(n) \ + (*(MD5_u32plus *)&ptr[(n) * 4]) +#define GET(n) \ + SET(n) +#else +#define SET(n) \ + (ctx->block[(n)] = \ + (MD5_u32plus)ptr[(n) * 4] | \ + ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \ + ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \ + ((MD5_u32plus)ptr[(n) * 4 + 3] << 24)) +#define GET(n) \ + (ctx->block[(n)]) +#endif + +/* + * This processes one or more 64-byte data blocks, but does NOT update the bit + * counters. There are no alignment requirements. + */ +static const void *body(MD5_CTX *ctx, const void *data, unsigned long size) +{ + const unsigned char *ptr; + MD5_u32plus a, b, c, d; + MD5_u32plus saved_a, saved_b, saved_c, saved_d; + + ptr = (const unsigned char *)data; + + a = ctx->a; + b = ctx->b; + c = ctx->c; + d = ctx->d; + + do { + saved_a = a; + saved_b = b; + saved_c = c; + saved_d = d; + +/* Round 1 */ + STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7) + STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12) + STEP(F, c, d, a, b, SET(2), 0x242070db, 17) + STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22) + STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7) + STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12) + STEP(F, c, d, a, b, SET(6), 0xa8304613, 17) + STEP(F, b, c, d, a, SET(7), 0xfd469501, 22) + STEP(F, a, b, c, d, SET(8), 0x698098d8, 7) + STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12) + STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17) + STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22) + STEP(F, a, b, c, d, SET(12), 0x6b901122, 7) + STEP(F, d, a, b, c, SET(13), 0xfd987193, 12) + STEP(F, c, d, a, b, SET(14), 0xa679438e, 17) + STEP(F, b, c, d, a, SET(15), 0x49b40821, 22) + +/* Round 2 */ + STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5) + STEP(G, d, a, b, c, GET(6), 0xc040b340, 9) + STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14) + STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20) + STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5) + STEP(G, d, a, b, c, GET(10), 0x02441453, 9) + STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14) + STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20) + STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5) + STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9) + STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14) + STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20) + STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5) + STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9) + STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14) + STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20) + +/* Round 3 */ + STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4) + STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11) + STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16) + STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23) + STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4) + STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11) + STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16) + STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23) + STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4) + STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11) + STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16) + STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23) + STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4) + STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11) + STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16) + STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23) + +/* Round 4 */ + STEP(I, a, b, c, d, GET(0), 0xf4292244, 6) + STEP(I, d, a, b, c, GET(7), 0x432aff97, 10) + STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15) + STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21) + STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6) + STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10) + STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15) + STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21) + STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6) + STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10) + STEP(I, c, d, a, b, GET(6), 0xa3014314, 15) + STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21) + STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6) + STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10) + STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15) + STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21) + + a += saved_a; + b += saved_b; + c += saved_c; + d += saved_d; + + ptr += 64; + } while (size -= 64); + + ctx->a = a; + ctx->b = b; + ctx->c = c; + ctx->d = d; + + return ptr; +} + +void MD5_Init(MD5_CTX *ctx) +{ + ctx->a = 0x67452301; + ctx->b = 0xefcdab89; + ctx->c = 0x98badcfe; + ctx->d = 0x10325476; + + ctx->lo = 0; + ctx->hi = 0; +} + +void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size) +{ + MD5_u32plus saved_lo; + unsigned long used, available; + + saved_lo = ctx->lo; + if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) + ctx->hi++; + ctx->hi += size >> 29; + + used = saved_lo & 0x3f; + + if (used) { + available = 64 - used; + + if (size < available) { + memcpy(&ctx->buffer[used], data, size); + return; + } + + memcpy(&ctx->buffer[used], data, available); + data = (const unsigned char *)data + available; + size -= available; + body(ctx, ctx->buffer, 64); + } + + if (size >= 64) { + data = body(ctx, data, size & ~(unsigned long)0x3f); + size &= 0x3f; + } + + memcpy(ctx->buffer, data, size); +} + +#define OUT(dst, src) \ + (dst)[0] = (unsigned char)(src); \ + (dst)[1] = (unsigned char)((src) >> 8); \ + (dst)[2] = (unsigned char)((src) >> 16); \ + (dst)[3] = (unsigned char)((src) >> 24); + +void MD5_Final(unsigned char *result, MD5_CTX *ctx) +{ + unsigned long used, available; + + used = ctx->lo & 0x3f; + + ctx->buffer[used++] = 0x80; + + available = 64 - used; + + if (available < 8) { + memset(&ctx->buffer[used], 0, available); + body(ctx, ctx->buffer, 64); + used = 0; + available = 64; + } + + memset(&ctx->buffer[used], 0, available - 8); + + ctx->lo <<= 3; + OUT(&ctx->buffer[56], ctx->lo) + OUT(&ctx->buffer[60], ctx->hi) + + body(ctx, ctx->buffer, 64); + + OUT(&result[0], ctx->a) + OUT(&result[4], ctx->b) + OUT(&result[8], ctx->c) + OUT(&result[12], ctx->d) + + memset(ctx, 0, sizeof(*ctx)); +} + +#endif diff --git a/src/md5.h b/src/md5.h new file mode 100644 index 0000000..76d31fc --- /dev/null +++ b/src/md5.h @@ -0,0 +1,52 @@ +/* + * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. + * MD5 Message-Digest Algorithm (RFC 1321). + * + * Homepage: + * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 + * + * Author: + * Alexander Peslyak, better known as Solar Designer + * + * This software was written by Alexander Peslyak in 2001. No copyright is + * claimed, and the software is hereby placed in the public domain. + * In case this attempt to disclaim copyright and place the software in the + * public domain is deemed null and void, then the software is + * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the + * general public under the following terms: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted. + * + * There's ABSOLUTELY NO WARRANTY, express or implied. + * + * See md5.c for more information. + */ + +#ifdef HAVE_OPENSSL +#include +#elif !defined(_MD5_H) +#define _MD5_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Any 32-bit or wider unsigned integer data type will do */ +typedef unsigned int MD5_u32plus; + +typedef struct { + MD5_u32plus lo, hi; + MD5_u32plus a, b, c, d; + unsigned char buffer[64]; + MD5_u32plus block[16]; +} MD5_CTX; + +extern void MD5_Init(MD5_CTX *ctx); +extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size); +extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); + +#ifdef __cplusplus +} +#endif +#endif