diff --git a/source/doc/changelog b/source/doc/changelog deleted file mode 100644 index 548139f..0000000 --- a/source/doc/changelog +++ /dev/null @@ -1,22 +0,0 @@ - - [04/20/03] - - Modified 68000 emulator to prevent 'tas.b $mem' from writing data back - after a read (fixes Gargoyles). - - Fixed bug in 68000 emulator to swap order of words written for address - register indirect pre-decremented writes (fixes Jim Power graphics). - - Added support for 240-line displays (for Super Skidmarks). - - Rewrote part of the interrupt handling (fixes some raster effects). - - Removed sprite collision detection code (never really worked). - - Optimized sprite rendering inner loop. - - [04/13/03] - - Finished up memory map for VDP DMA V-bus reads. - - Fixed handling of 68000 writes to I/O chip at even addresses. - - Fixed bit 7 handling of control register in I/O chip. - - Finished up Z80 memory map. - - Added code to handle Genesis hardware lock-ups. - - Removed some faulty code from the 68000 memory map handlers. - - [03/22/03] - - Completed implementation of Z80 banked memory handlers. - diff --git a/source/doc/license b/source/doc/license deleted file mode 100644 index f89b4fa..0000000 --- a/source/doc/license +++ /dev/null @@ -1,340 +0,0 @@ - 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) 19yy - - This program is free software; you can redistribute it and/or modify - 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) 19yy 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/source/doc/porting.txt b/source/doc/porting.txt deleted file mode 100644 index 4a92903..0000000 --- a/source/doc/porting.txt +++ /dev/null @@ -1,89 +0,0 @@ - - Introduction - - Genesis Plus has reasonable speed, and very fast rendering. Here are some - details about porting it to another platform - - Porting rules - - - This program is released under the GPL, so please release the source - code for your derivative ports. Let me know if you need an alternative - to this. - - - Do not change the name of the emulator. Something like 'Genesis Plus / MacOS' - is fine as it keeps the original name. - - - Configure the CPU emulators for little or big-endian CPUs, and use the - ALIGN_LONG option to handle unaligned memory accesses if needed. E.g. if - the emulator crashes when a game scrolls horizontally, you need to enable - it. - - Requirements - - - At this time the 16-bit rendering code has been well tested and should - be used. There is code to support 8 through 32-bit displays, but I - haven't checked if it still works. - - - Audio output, if enabled, uses stereo 16-bit samples. - - Functions to use: - - int load_rom(char *filename); - - Loads a game which can be in BIN, SMD or ZIP formats. It returns zero if - an error has occured. - - void system_init(void); - - Initializes the virtual Genesis console. Call this once during startup. - - void audio_init(int rate); - - Initialize the sound emulation part of the emulator. Pass zero or don't - call the function to disable sound. Call this after running system_init(). - - void system_reset(void); - - Resets the virtual Genesis console. Call this once during setup, and later - as needed. - - int system_frame(int skip); - - Updates the emulation for a frame. Pass 1 to prevent rendering (which can - be used for frame skipping) and 0 to render the current display. - - This function returns 0 if the virtual Genesis console has locked up. - You can do what you'd like with this information, such as notify the user, - reset the machine, etc. - - If audio is enabled, the snd.buffer[] array will hold the current audio - data for this frame. - - void system_shutdown(void); - - Shuts down the emulator. - - Variables: - - The 'bitmap' structure needs to be filled out prior to calling system_init(). - This provides the rendering code with information about the type of bitmap - it is rendering to. I would advise sticking with a 1024x512 16-bit bitmap: - - memset(&bitmap, 0, sizeof(t_bitmap)); - bitmap.width = 1024; - bitmap.height = 512; - bitmap.depth = 16; - bitmap.granularity = 2; /* Bytes per pixel */ - bitmap.pitch = (bitmap.width * bitmap.granularity); - bitmap.data = (unsigned char *)bmp->pixels; /* Pointer to your bitmap */ - bitmap.viewport.w = 256; /* Initial size of display on power-up (do not change) */ - bitmap.viewport.h = 224; - bitmap.viewport.x = 0x20; /* Offset used for rendering (do not change) */ - bitmap.viewport.y = 0x00; - bitmap.remap = 1; - - The variable 'input.pad[0]' holds the button states for the first player - gamepad. Update this prior to calling system_frame(), and use the bitmasks - defined in system.h such as 'INPUT_UP', etc. - - See the Windows/SDL and DOS drivers for examples. diff --git a/source/doc/readme.txt b/source/doc/readme.txt deleted file mode 100644 index 130800d..0000000 --- a/source/doc/readme.txt +++ /dev/null @@ -1,122 +0,0 @@ - ---------------------------------------------------------------------------- - Genesis Plus - ---------------------------------------------------------------------------- - - Version 1.2a - by Charles Mac Donald - WWW: http://cgfm2.emuviews.com - - What's New - ---------- - - [06/22/03] - - Modified rendering code for portability - - Modified memory handling to fix banked PSG access - [05/13/03] - - Initial release - - Usage - ----- - - The Windows version runs windowed in a 16-bit desktop with NO sound or - joystick support. - - The DOS version has most of the functionality from SMS Plus, such - as audio, joysticks, etc. - - Windows/DOS controls: - - Arrow Keys - Directional pad - A,S,D,F - 1P gamepad, buttons A, B, C, Start - Tab - Reset - Esc - Exit program - - DOS only: - - End - Exit program - F1-F4 - Set frameskip level (F1 = no skip ... F4 = skip 3 frames) - F8 - Make PCX screen snapshot - F9 - Toggle VSync - F10 - Toggle speed throttling - F11 - Toggle FPS meter - - DOS details: - - You can only support a second player if you are using a joystick driver - that supports more than one joystick. (e.g. Sidewinder, dual pads, etc.) - - Type 'gen -help' on the command line for a list of useful options. - - -res set the display resolution. - -vdriver specify video driver. - -depth specify color depth. (8, 16) - -scanlines use scanlines effect. - -scale scale display to full resolution. (slow) - -vsync wait for vertical sync before blitting. - -sound enable sound. (force speed throttling) - -sndrate specify sound rate. (8000, 11025, 22050, 44100) - -sndcard specify sound card. (0-7) - -swap swap left and right stereo output. - -joy specify joystick type. - - Here is a list of all the video drivers you can pass as a parameter - to the '-vdriver' option: - - auto, safe, vga, modex, vesa2l, vesa3, vbeaf - - Here is a list of all the joystick drivers you can pass as a parameter - to the '-joy' option: - - auto, none, standard, 2pads, 4button, 6button, 8button, fspro, wingex, - sidewinder, gamepadpro, grip, grip4, sneslpt1, sneslpt2, sneslpt3, - psxlpt1, psxlpt2, psxlpt3, n64lpt1, n64lpt2, n64lpt3, db9lpt1, db9lpt2, - db9lpt3, tglpt1, tglpt2, tglpt3, wingwar, segaisa, segapci, segapci2 - - You can put any commandline option into a plain text file which should - be called "gen.cfg". Put one option per line, please. Command line options - will override anything in the configuration file. - - Currently the zip loading code can manage a zipfile where the game - image is the first thing in it. If you try to open a huge archive of - games, only the first will be played. - - Credits and Acknowlegements - --------------------------- - - I would like to thank Omar Cornut, Christian Schiller, and Chris MacDonald - for their invaluable help and support with this project. - - Richard Bannister for the Macintosh port and all of the code fixes and - suggestions that have made Genesis Plus a better program. - (http://www.bannister.org) - - The Genesis emulator authors: Bart Trzynadlowski, Quintesson, Steve Snake, - James Ponder, Stef, Gerrie, Sardu. - - The regular people and many lurkers at segadev. - - The MAME team for the CPU and sound chip emulators. - - Everyone who has contributed, donated, and submitted information to help - out Genesis Plus and my efforts documenting the Genesis hardware. - - Contact - ------- - - Charles MacDonald - E-mail: cgfm2@hotmail.com - WWW: http://cgfm2.emuviews.com - - Legal - ----- - - Copyright (C) 1999, 2000, 2001, 2002, 2003 Charles MacDonald - - The source code is distributed under the terms of the GNU General Public - License. - - The Z80 CPU emulator, 68K CPU emulator, and the PSG, YM2612 emulation code - are taken from the MAME project, and terms of their use are covered under - the MAME license. - (http://www.mame.net) - diff --git a/source/doc/todo.txt b/source/doc/todo.txt deleted file mode 100644 index 624ba22..0000000 --- a/source/doc/todo.txt +++ /dev/null @@ -1,79 +0,0 @@ - - Here are some technical details about things that need to be fixed or - added to Genesis Plus. - - Missing features: - - - Support for 6-button controllers - - SRAM management - - Game Genie / PAR patch codes - - The VDP code could use a lot of cleaning up. - - The rendering code is missing a few bits: - - - Sprite collision - - Window bug - - I think the "C" 68000 emulator either has some bugs or I'm not using it - correctly. Older DOS-only versions used Turbo68K, which had ran games - much better, especially with regards to interrupt handling. - - Things that need to be fixed: - - - Raster garbage on third road in Thunder Blade. - - - Added country codes for Dragon Slayer, but game locks up after - passing country check. - - - No inputs in Samurai Shodown. - (This game doesn't initialize the port direction registers, at least not - directly. Emulation bug or problem with the game?) - - - Palette and raster problems in Mortal Kombat. - - - Bad raster effects and VRAM corruption in Super Skidmarks. - (Needs PAL timing) - - - Palette problems in Sonic 2 title screen. - - - Masked half of Sonic sprite visible on Sonic title screen. - - - Sprite masking doesn't work in Micro Machines subscreen. - - - Music has slow tempo in Batman & Robin. (doesn't seem to be a problem - with the YM2612 timers - Wonderboy 3 is normal) - - - Music has jerky playback in Sonic 2, 3, 3D Blast. If you run the Z80 - emulation for one scanline after requesting an interrupt, it runs fine. - - - DAC and PSG output are too loud, both are divided by two for now - (though the PSG should be a bit quieter and the DAC a bit louder) - - - Undead Line locks after selecting a stage, also the Z80 sound halts - after the first note is played. - - This game single steps the Z80 with the following code: - - MOVEM.L D0,-(A7) ; 009C7C 48 E7 80 00 - ORI #$0200,SR ; 009C80 00 7C 02 00 -; Get control of the Z-bus - MOVE.W #$0100,$00A11100 ; 009C84 33 FC 01 00 00 A1 11 00 - BTST #$00,$00A11100 ; 009C8C 08 39 00 00 00 A1 11 00 - BNE.S *-$08 [00009C8C] ; 009C94 66 F6 -; Check driver status byte. If zero, release bus and exit. - TST.B $00A00008 ; 009C96 4A 39 00 A0 00 08 - BEQ *+$0016 [00009CB2] ; 009C9C 67 00 00 14 -; Release bus and wait for Z80 to resume control. Then restart the loop -; and immediately get the bus back again, assuming the Z80 ran at least -; one instruction in the meantime. - CLR.W $00A11100 ; 009CA0 42 79 00 A1 11 00 - BTST #$00,$00A11100 ; 009CA6 08 39 00 00 00 A1 11 00 - BEQ.S *-$08 [00009CA6] ; 009CAE 67 F6 - BRA.S *-$2C [00009C84] ; 009CB0 60 D2 -; Release bus and exit. - CLR.W $00A11100 ; 009CB2 42 79 00 A1 11 00 - ANDI #$FDFF,SR ; 009CB8 02 7C FD FF - MOVEM.L (A7)+,D0 ; 009CBC 4C DF 00 01 - RTS ; 009CC0 4E 75 - diff --git a/source/input.c b/source/gen_input.c similarity index 100% rename from source/input.c rename to source/gen_input.c diff --git a/source/input.h b/source/gen_input.h similarity index 96% rename from source/input.h rename to source/gen_input.h index 78e5033..4254bd5 100644 --- a/source/input.h +++ b/source/gen_input.h @@ -21,8 +21,8 @@ * ****************************************************************************************/ -#ifndef _INPUT_HW_H_ -#define _INPUT_HW_H_ +#ifndef _GEN_INPUT_H_ +#define _GEN_INPUT_H_ /* Max. number of devices */ #define MAX_DEVICES (8) diff --git a/source/io.c b/source/gen_io.c similarity index 100% rename from source/io.c rename to source/gen_io.c diff --git a/source/io.h b/source/gen_io.h similarity index 94% rename from source/io.h rename to source/gen_io.h index 79c3822..0736c59 100644 --- a/source/io.h +++ b/source/gen_io.h @@ -21,8 +21,8 @@ * ****************************************************************************************/ -#ifndef _IO_H_ -#define _IO_H_ +#ifndef _GEN_IO_H_ +#define _GEN_IO_H_ #define REGION_USA 0x80 #define REGION_JAPAN_NTSC 0x00 diff --git a/source/ngc/config.h b/source/ngc/config.h index 011a3a3..aac746a 100644 --- a/source/ngc/config.h +++ b/source/ngc/config.h @@ -12,6 +12,7 @@ typedef struct double psg_preamp; double fm_preamp; uint8 boost; + uint8 filter; uint8 hq_fm; uint8 fm_core; int8 sram_auto; diff --git a/source/ngc/gui/fileio.c b/source/ngc/fileio.c similarity index 100% rename from source/ngc/gui/fileio.c rename to source/ngc/fileio.c diff --git a/source/ngc/gui/fileio.h b/source/ngc/fileio.h similarity index 100% rename from source/ngc/gui/fileio.h rename to source/ngc/fileio.h diff --git a/source/ngc/gui/memfile.c b/source/ngc/memfile.c similarity index 100% rename from source/ngc/gui/memfile.c rename to source/ngc/memfile.c diff --git a/source/shared.h b/source/shared.h index 0c1b993..daaba21 100644 --- a/source/shared.h +++ b/source/shared.h @@ -17,8 +17,8 @@ #include "memz80.h" #include "membnk.h" #include "memvdp.h" -#include "io.h" -#include "input.h" +#include "gen_io.h" +#include "gen_input.h" #include "state.h" #include "sound.h" #include "sn76489.h" diff --git a/source/sound/SRC/config.h b/source/sound/SRC/config.h index 5a9a804..a309cf8 100644 --- a/source/sound/SRC/config.h +++ b/source/sound/SRC/config.h @@ -49,7 +49,11 @@ #undef HAVE_LIBM /* Define if you have C99's lrint function. */ +#ifdef DOS +#define HAVE_LRINT 0 +#else #define HAVE_LRINT 1 +#endif /* Define if you have C99's lrintf function. */ #define HAVE_LRINTF 1 diff --git a/source/sound/fm.c b/source/sound/fm.c index 923de8d..37d2dad 100644 --- a/source/sound/fm.c +++ b/source/sound/fm.c @@ -787,11 +787,28 @@ INLINE void set_tl(FM_CH *CH,FM_SLOT *SLOT , int v) /* set attack rate & key scale */ INLINE void set_ar_ksr(FM_CH *CH,FM_SLOT *SLOT,int v) { - SLOT->ar = (v&0x1f) ? (32 + ((v&0x1f)<<1)) : 0; + UINT8 old_KSR = SLOT->KSR; + + SLOT->ar = (v&0x1f) ? 32 + ((v&0x1f)<<1) : 0; SLOT->KSR = 3-(v>>6); - CH->SLOT[SLOT1].Incr=-1; -} + if (SLOT->KSR != old_KSR) + { + CH->SLOT[SLOT1].Incr=-1; + } + + /* refresh Attack rate */ + if ((SLOT->ar + SLOT->ksr) < 94 /*32+62*/) + { + SLOT->eg_sh_ar = eg_rate_shift [SLOT->ar + SLOT->ksr ]; + SLOT->eg_sel_ar = eg_rate_select[SLOT->ar + SLOT->ksr ]; + } + else + { + SLOT->eg_sh_ar = 0; + SLOT->eg_sel_ar = 17*RATE_STEPS; + } + } /* set decay rate */ INLINE void set_dr(FM_SLOT *SLOT,int v) diff --git a/source/sound/ym2612.c b/source/sound/ym2612.c index 69c7a3d..dcd24c1 100644 --- a/source/sound/ym2612.c +++ b/source/sound/ym2612.c @@ -2373,11 +2373,8 @@ void YM2612_Update(int **buf, int length) { for(i = 0; i < length; i++) { - long dac = (YM2612.DACdata << 15) - dac_highpass; - dac_highpass += dac >> 9; - dac >>= 15; - buf[0][i] += dac & YM2612.CHANNEL[5].LEFT; - buf[1][i] += dac & YM2612.CHANNEL[5].RIGHT; + buf[0][i] += YM2612.DACdata & YM2612.CHANNEL[5].LEFT; + buf[1][i] += YM2612.DACdata & YM2612.CHANNEL[5].RIGHT; } } diff --git a/source/system.c b/source/system.c index 0e5cf41..b5c810e 100644 --- a/source/system.c +++ b/source/system.c @@ -337,7 +337,8 @@ static void audio_update (void) int l, r; double psg_preamp = config.psg_preamp; double fm_preamp = config.fm_preamp; - uint8 boost = config.boost; + int boost = config.boost; + int filter = config.filter; #ifdef NGC int16 *sb = (int16 *) soundbuffer[mixbuffer]; @@ -357,8 +358,13 @@ static void audio_update (void) snd.psg.buffer[i] = 0; /* single-pole low-pass filter (6 dB/octave) */ - ll = (ll + l) >> 1; - rr = (rr + r) >> 1; + if (filter) + { + l = (ll + l) >> 1; + r = (rr + r) >> 1; + ll = l; + rr = r; + } /* boost volume if asked*/ l = ll * boost; @@ -374,7 +380,7 @@ static void audio_update (void) #ifdef NGC *sb++ = r; // RIGHT channel comes first *sb++ = l; -#else +#elif DOS snd.buffer[0][i] = l; snd.buffer[1][i] = r; #endif diff --git a/source/types.h b/source/types.h index ee6a713..5be1c38 100644 --- a/source/types.h +++ b/source/types.h @@ -16,9 +16,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _TYPES_H_ -#define _TYPES_H_ - #undef uint8 #undef uint16 #undef uint32 @@ -30,4 +27,3 @@ #define int16 signed short #define int32 signed long int -#endif /* _TYPES_H_ */ diff --git a/source/unused/makefile.dj2 b/source/unused/dos/Makefile similarity index 56% rename from source/unused/makefile.dj2 rename to source/unused/dos/Makefile index 8c822c9..97b7958 100644 --- a/source/unused/makefile.dj2 +++ b/source/unused/dos/Makefile @@ -1,28 +1,36 @@ -# MekaDrive - Sega Mega Drive emulator +# Makefile for genplus DOS +# # (c) 1999, 2000, 2001, 2002, 2003 Charles MacDonald - +# modified by Eke-Eke +# +# Defines : # -DLSB_FIRST - Leave undefined for big-endian processors. # -DDOS - Enable DOS/x86 specific code. # -DDEBUG - Enable debugging code # -DX86_ASM - Enable inline x86 assembly code in Z80 emulator -CC = gcc +CC = gcc AS = nasm -f coff LDFLAGS = -FLAGS = -I. -Icpu -Im68k -Idos -Isound -Icart_hw -Icart_hw\svp \ - -Werror -Wall \ - -O6 -mcpu=pentium -fomit-frame-pointer \ +FLAGS = -I. -I.. -I../cpu -I../m68k -I../dos -I../sound -I../sound/SRC -I../cart_hw -I../cart_hw/svp \ + -Wall -g \ + -O6 -march=i686 -fomit-frame-pointer \ -DLSB_FIRST -DX86_ASM -DDOS -LIBS = -lalleg -laudio -lz obj/m68k.oa +LIBS = -lalleg -laudio -lz -lm -OBJ = obj/z80.oa \ - obj/genesis.o \ +OBJ = obj/z80.o + +OBJ += obj/m68kcpu.o \ + obj/m68kops.o + + +OBJ += obj/genesis.o \ obj/vdp.o \ obj/render.o \ obj/system.o \ - obj/io.o \ - obj/input.o \ + obj/gen_io.o \ + obj/gen_input.o \ obj/mem68k.o \ obj/memz80.o \ obj/membnk.o \ @@ -34,6 +42,12 @@ OBJ += obj/sound.o \ obj/sn76489.o \ obj/ym2612.o + +OBJ += obj/samplerate.o \ + obj/src_linear.o \ + obj/src_sinc.o \ + obj/src_zoh.o \ + OBJ += obj/sram.o \ obj/eeprom.o \ obj/svp.o \ @@ -54,34 +68,39 @@ all : $(EXE) $(EXE) : $(OBJ) $(CC) -o $(EXE) $(OBJ) $(LIBS) $(LDFLAGS) - -obj/%.oa : cpu/%.c cpu/%.h - $(CC) -c $< -o $@ $(FLAGS) -obj/%.o : %.c %.h +obj/%.o : ../%.c ../%.h $(CC) -c $< -o $@ $(FLAGS) -obj/%.o : asm/%.s +obj/%.o : ../asm/%.s $(AS) $< -o $@ -obj/%.o : sound/%.c sound/%.h +obj/%.o : ../sound/%.c ../sound/%.h $(CC) -c $< -o $@ $(FLAGS) -obj/%.o : sound/%.c +obj/%.o : ../sound/%.c $(CC) -c $< -o $@ $(FLAGS) -obj/%.o : cart_hw/%.c cart_hw/%.h +obj/%.o : ../sound/SRC/%.c ../sound/SRC/%.h + $(CC) -c $< -o $@ $(FLAGS) +obj/%.o : ../sound/SRC/%.c $(CC) -c $< -o $@ $(FLAGS) -obj/%.o : cart_hw/svp/%.c +obj/%.o : ../cart_hw/%.c ../cart_hw/%.h $(CC) -c $< -o $@ $(FLAGS) -obj/%.o : cart_hw/svp/%.c cart_hw/svp/%.h +obj/%.o : ../cart_hw/svp/%.c $(CC) -c $< -o $@ $(FLAGS) -obj/%.o : cpu/%.c cpu/%.h +obj/%.o : ../cart_hw/svp/%.c ../cart_hw/svp/%.h $(CC) -c $< -o $@ $(FLAGS) -obj/%.o : dos/%.c dos/%.h +obj/%.o : ../cpu/%.c ../cpu/%.h + $(CC) -c $< -o $@ $(FLAGS) + +obj/%.o : ../m68k/%.c ../m68k/%.h + $(CC) -c $< -o $@ $(FLAGS) + +obj/%.o : ./%.c ./%.h $(CC) -c $< -o $@ $(FLAGS) pack : diff --git a/source/unused/dos/config.c b/source/unused/dos/config.c index bf7700d..6646390 100644 --- a/source/unused/dos/config.c +++ b/source/unused/dos/config.c @@ -1,6 +1,8 @@ #include "osd.h" +#define CONFIG_VERSION "GENPLUS 1.2.1 " + t_option option; t_config config; @@ -70,9 +72,9 @@ int check_bool(char *token) void set_option_defaults(void) { option.video_driver = GFX_AUTODETECT; - option.video_width = 320; - option.video_height = 240; - option.video_depth = 8; + option.video_width = 640; + option.video_height = 480; + option.video_depth = 16; option.remap = 1; option.scanlines = 0; @@ -90,13 +92,16 @@ void set_option_defaults(void) option.joy_driver = JOY_TYPE_NONE; } -/* additional options */ -void set_config_default() +void set_config_defaults(void) { + /* version TAG */ + strncpy(config.version,CONFIG_VERSION,15); + /* sound options */ config.psg_preamp = 1.5; config.fm_preamp = 1.0; config.boost = 1; + config.filter = 0; config.hq_fm = 1; config.fm_core = 0; @@ -110,16 +115,15 @@ void set_config_default() /* display options */ config.xshift = 0; config.yshift = 0; - config.xscale = 320; - config.yscale = 240; + config.xscale = 0; + config.yscale = 0; config.aspect = 1; config.overscan = 1; config.render = 0; /* controllers options */ - config.sys_type[0] = 0; - config.sys_type[1] = 0; - config.crosshair = 1; + config.gun_cursor = 1; + config.invert_mouse = 0; } void print_options(void) @@ -232,7 +236,7 @@ void parse_args(int argc, char **argv) } } - //if(option.remap) option.video_depth = 8; + if(option.remap) option.video_depth = 8; } diff --git a/source/unused/dos/config.h b/source/unused/dos/config.h index 36e6d54..2772098 100644 --- a/source/unused/dos/config.h +++ b/source/unused/dos/config.h @@ -48,12 +48,17 @@ typedef struct int softres; /* 1= Allow RUN+SELECT */ } t_option; +/**************************************************************************** + * Config Option + * + ****************************************************************************/ typedef struct { - char[10] version; + char version[15]; double psg_preamp; double fm_preamp; - uint8 boost; + uint8 boost; + uint8 filter; uint8 hq_fm; uint8 fm_core; int8 sram_auto; @@ -69,8 +74,8 @@ typedef struct uint8 aspect; uint8 overscan; uint8 render; - uint8 sys_type[2]; - uint8 crosshair; + uint8 gun_cursor; + uint8 invert_mouse; } t_config; /* Global variables */ @@ -86,7 +91,7 @@ void parse_args(int argc, char **argv); void print_options(void); int check_bool(char *token); void set_option_defaults(void); -void set_config_default(void); +void set_config_defaults(void); #endif /* _CONFIG_H_ */ diff --git a/source/unused/dos/dos.c b/source/unused/dos/dos.c index 6906868..d2fbee5 100644 --- a/source/unused/dos/dos.c +++ b/source/unused/dos/dos.c @@ -14,7 +14,7 @@ PALETTE gen_pal; BITMAP *gen_bmp; volatile int frame_skip = 1; -int frame_count = 0; +volatile int frame_count = 0; volatile int frames_rendered = 0; volatile int frame_rate = 0; volatile int tick_count = 0; @@ -22,7 +22,7 @@ volatile int old_tick_count = 0; volatile int skip = 0; int quit = 0; -unsigned char buf[0x26000]; +unsigned char buf[0x24000]; uint8 log_error = 1; uint8 debug_on = 0; @@ -50,35 +50,42 @@ void msg_print(int x, int y, char *fmt, ...) int main (int argc, char *argv[]) { - if(argc < 2) { - printf("Genesis Plus - Sega Mega Drive emulator (v1.0)\n"); - printf("(C) 1999, 2000, 2001, 2002, 2003 Charles MacDonald\n"); - printf("Usage %s file.[bin|smd|zip] [-options]\n", argv[0]); - printf("Type `%s -help' for a list of options.\n", argv[0]); - exit(1); - }; + if(argc < 2) + { + printf("Genesis Plus - Sega Mega Drive emulator (v1.0)\n"); + printf("(C) 1999, 2000, 2001, 2002, 2003 Charles MacDonald\n"); + printf("Usage %s file.[bin|smd|zip] [-options]\n", argv[0]); + printf("Type `%s -help' for a list of options.\n", argv[0]); + exit(1); + }; - if(stricmp(argv[1], "-help") == 0) - { - print_options(); - return (0); - } - error_init(); + if(stricmp(argv[1], "-help") == 0) + { + print_options(); + return (0); + } + error_init(); - cart_rom = malloc(0xA00000); - memset(cart_rom, 0, 0xA00000); + cart_rom = malloc(0xA00000); + memset(cart_rom, 0, 0xA00000); - set_config_default(); + if(!load_rom(argv[1])) + { + printf("File `%s' not found.\n", argv[1]); + return (0); + } - if(!load_rom(argv[1])) - { - printf("File `%s' not found.\n", argv[1]); - return (0); - } + /* load SRAM */ + FILE *f = fopen("./game.srm", "rb"); + if (f!=NULL) + { + fread(&sram.sram,0x10000,1, f); + fclose(f); + } - - memset(bios_rom, 0, sizeof(bios_rom)); - FILE *f = fopen("./BIOS.bin", "rb"); + /* load BIOS */ + memset(bios_rom, 0, sizeof(bios_rom)); + f = fopen("./BIOS.bin", "rb"); if (f!=NULL) { fread(&bios_rom, 0x800,1,f); @@ -91,65 +98,58 @@ int main (int argc, char *argv[]) bios_rom[i+1] = temp; } config.bios_enabled = 3; - } + } else config.bios_enabled = 0; - init_machine(); - set_config_default(); - input.system[0] = SYSTEM_GAMEPAD; - input.system[1] = SYSTEM_GAMEPAD; - - system_init(); + /* initialize genesis VM */ + init_machine(); + + /* default config */ + set_config_defaults(); + input.system[0] = SYSTEM_GAMEPAD; + input.system[1] = SYSTEM_GAMEPAD; + /* initialize emulation */ int buf_len = (option.sndrate * 4) / vdp_rate; snd.buffer[0] = malloc (buf_len/2); snd.buffer[1] = malloc (buf_len/2); memset (snd.buffer[0], 0, buf_len/2); memset (snd.buffer[1], 0, buf_len/2); + system_init(); audio_init(option.sndrate); - - f = fopen("./game.srm", "rb"); - if (f!=NULL) - { - fread(&sram.sram,0x10000,1, f); - fclose(f); - } - - system_reset(); - for(;;) + /* emulation loop */ + for(;;) + { + frame_count += 1; + if(quit) break; + if(frame_count % frame_skip == 0) { - frame_count += 1; - if(quit) break; - if(frame_count % frame_skip == 0) - { - system_frame(0); - frames_rendered++; + system_frame(0); + frames_rendered++; dos_update_video(); - } - else - { - system_frame(1); - } - if(option.sound) dos_update_audio(); + } + else + { + system_frame(1); + } + if(option.sound) dos_update_audio(); //error("%d\n", frame_rate); } f = fopen("./game.srm", "wb"); - if (f!=NULL) - { - fwrite(&sram.sram, 0x10000,1,f); - fclose(f); - - } - + if (f!=NULL) + { + fwrite(&sram.sram, 0x10000,1,f); + fclose(f); + } trash_machine(); - system_shutdown(); - error_shutdown(); - return (0); + system_shutdown(); + error_shutdown(); + return (0); } /* Timer handler */ @@ -185,127 +185,176 @@ int save_file(char *filename, char *buf, int size) static int joynum = 0; uint8 delay = 36; +int gun_offset = 0; + +int old_mouse_x = 0; +int old_mouse_y = 0; + void dos_update_input(void) { - FILE *f; + FILE *f; if(key[KEY_ESC] || key[KEY_END]) - { - quit = 1; - } + { + quit = 1; + } while (input.dev[joynum] == NO_DEVICE) { - joynum ++; - if (joynum > MAX_DEVICES - 1) joynum = 0; + joynum ++; + if (joynum > MAX_DEVICES - 1) joynum = 0; } + if(check_key(KEY_F12)) + { + input.x_offset ++; + if (input.x_offset > 0xff) input.x_offset = 0; + } + if(check_key(KEY_F11)) + { + + joynum ++; + if (joynum > MAX_DEVICES - 1) joynum = 0; + + while (input.dev[joynum] == NO_DEVICE) + { + joynum ++; + if (joynum > MAX_DEVICES - 1) joynum = 0; + } + } + input.pad[joynum] = 0; - /* Is the joystick being used ? */ - if(option.joy_driver != JOY_TYPE_NONE) - { - poll_joystick(); - - /* Check player 1 joystick */ - if(joy[0].stick[0].axis[1].d1) input.pad[0] |= INPUT_UP; - else - if(joy[0].stick[0].axis[1].d2) input.pad[0] |= INPUT_DOWN; - - if(joy[0].stick[0].axis[0].d1) input.pad[0] |= INPUT_LEFT; - else - if(joy[0].stick[0].axis[0].d2) input.pad[0] |= INPUT_RIGHT; - - if(joy[0].button[0].b) input.pad[0] |= INPUT_A; - if(joy[0].button[1].b) input.pad[0] |= INPUT_B; - if(joy[0].button[2].b) input.pad[0] |= INPUT_C; - if(joy[0].button[3].b) input.pad[0] |= INPUT_START; - if(joy[0].button[4].b) input.pad[0] |= INPUT_X; - if(joy[0].button[5].b) input.pad[0] |= INPUT_Y; - if(joy[0].button[6].b) input.pad[0] |= INPUT_Z; - if(joy[0].button[7].b) input.pad[0] |= INPUT_MODE; - - /* More than one joystick supported ? */ - if(num_joysticks > 2) + /* Is the joystick being used ? */ + if(option.joy_driver != JOY_TYPE_NONE) { - /* Check player 2 joystick */ - if(joy[1].stick[0].axis[1].d1) input.pad[1] |= INPUT_UP; - else - if(joy[1].stick[0].axis[1].d2) input.pad[1] |= INPUT_DOWN; + poll_joystick(); - if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_LEFT; - else - if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_RIGHT; + /* Check player 1 joystick */ + if(joy[0].stick[0].axis[1].d1) input.pad[0] |= INPUT_UP; + else + if(joy[0].stick[0].axis[1].d2) input.pad[0] |= INPUT_DOWN; - if(joy[1].button[0].b) input.pad[1] |= INPUT_A; - if(joy[1].button[1].b) input.pad[1] |= INPUT_B; - if(joy[1].button[2].b) input.pad[1] |= INPUT_C; - if(joy[1].button[3].b) input.pad[1] |= INPUT_START; - if(joy[1].button[4].b) input.pad[1] |= INPUT_X; - if(joy[1].button[5].b) input.pad[1] |= INPUT_Y; - if(joy[1].button[6].b) input.pad[1] |= INPUT_Z; - if(joy[1].button[7].b) input.pad[1] |= INPUT_MODE; + if(joy[0].stick[0].axis[0].d1) input.pad[0] |= INPUT_LEFT; + else + if(joy[0].stick[0].axis[0].d2) input.pad[0] |= INPUT_RIGHT; + + if(joy[0].button[0].b) input.pad[0] |= INPUT_A; + if(joy[0].button[1].b) input.pad[0] |= INPUT_B; + if(joy[0].button[2].b) input.pad[0] |= INPUT_C; + if(joy[0].button[3].b) input.pad[0] |= INPUT_START; + if(joy[0].button[4].b) input.pad[0] |= INPUT_X; + if(joy[0].button[5].b) input.pad[0] |= INPUT_Y; + if(joy[0].button[6].b) input.pad[0] |= INPUT_Z; + if(joy[0].button[7].b) input.pad[0] |= INPUT_MODE; + + /* More than one joystick supported ? */ + if(num_joysticks > 2) + { + /* Check player 2 joystick */ + if(joy[1].stick[0].axis[1].d1) input.pad[1] |= INPUT_UP; + else + if(joy[1].stick[0].axis[1].d2) input.pad[1] |= INPUT_DOWN; + + if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_LEFT; + else + if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_RIGHT; + + if(joy[1].button[0].b) input.pad[1] |= INPUT_A; + if(joy[1].button[1].b) input.pad[1] |= INPUT_B; + if(joy[1].button[2].b) input.pad[1] |= INPUT_C; + if(joy[1].button[3].b) input.pad[1] |= INPUT_START; + if(joy[1].button[4].b) input.pad[1] |= INPUT_X; + if(joy[1].button[5].b) input.pad[1] |= INPUT_Y; + if(joy[1].button[6].b) input.pad[1] |= INPUT_Z; + if(joy[1].button[7].b) input.pad[1] |= INPUT_MODE; + } } - } - /* keyboard */ - if(key[KEY_UP]) input.pad[joynum] |= INPUT_UP; - else - if(key[KEY_DOWN]) input.pad[joynum] |= INPUT_DOWN; + - if(key[KEY_LEFT]) input.pad[joynum] |= INPUT_LEFT; - else - if(key[KEY_RIGHT]) input.pad[joynum] |= INPUT_RIGHT; - if(key[KEY_A]) input.pad[joynum] |= INPUT_A; - if(key[KEY_S]) input.pad[joynum] |= INPUT_B; - if(key[KEY_D]) input.pad[joynum] |= INPUT_C; - if(key[KEY_Z]) input.pad[joynum] |= INPUT_X; + if(key[KEY_Z]) input.pad[joynum] |= INPUT_X; if(key[KEY_X]) input.pad[joynum] |= INPUT_Y; if(key[KEY_C]) input.pad[joynum] |= INPUT_Z; if(key[KEY_V]) input.pad[joynum] |= INPUT_MODE; - - if(key[KEY_F]) - { + if(key[KEY_UP]) input.pad[joynum] |= INPUT_UP; + else + if(key[KEY_DOWN]) input.pad[joynum] |= INPUT_DOWN; + if(key[KEY_LEFT]) input.pad[joynum] |= INPUT_LEFT; + else + if(key[KEY_RIGHT]) input.pad[joynum] |= INPUT_RIGHT; + if(check_key(KEY_A)) error("ButtonA pressed\n"); + if(key[KEY_A]) { + input.pad[joynum] |= INPUT_A; + } + if(key[KEY_S]) input.pad[joynum] |= INPUT_B; + if(key[KEY_D]) input.pad[joynum] |= INPUT_C; + if(check_key(KEY_F)) error("start pressed\n"); + if(key[KEY_F]) { + input.pad[joynum] |= INPUT_START; - error("start pressed\n"); - } - + } + + extern uint8 pico_current; if (input.dev[joynum] == DEVICE_LIGHTGUN) { /* Poll mouse if necessary */ if(mouse_needs_poll() == TRUE) poll_mouse(); - /* Calculate X Y axis values */ - input.analog[joynum - 4][0] = (mouse_x * bitmap.viewport.w) / SCREEN_W; - input.analog[joynum - 4][1] = (mouse_y * bitmap.viewport.h) / SCREEN_H; + /* Calculate X axis value */ + input.analog[joynum-4][0] = (mouse_x * bitmap.viewport.w)/SCREEN_W;; + + /* Calculate Y axis value */ + input.analog[joynum-4][1] = (mouse_y * bitmap.viewport.h)/SCREEN_H;; /* Map mouse buttons to player #1 inputs */ - if(mouse_b & 4) input.pad[joynum] |= INPUT_B; - if(mouse_b & 2) input.pad[joynum] |= INPUT_C; + if(mouse_b & 4) input.pad[joynum] |= INPUT_C; + if(mouse_b & 2) input.pad[joynum] |= INPUT_B; if(mouse_b & 1) input.pad[joynum] |= INPUT_A; + if(key[KEY_F]) input.pad[joynum] |= INPUT_START; } + else if (input.dev[joynum] == DEVICE_MOUSE) + { + /* Poll mouse if necessary */ + if(mouse_needs_poll() == TRUE) + poll_mouse(); + get_mouse_mickeys(&input.analog[2][0], &input.analog[2][1]); + input.analog[2][0] = (input.analog[2][0] * 256) / SCREEN_W; + input.analog[2][1] = (input.analog[2][1] * 256) / SCREEN_H; + if (config.invert_mouse) input.analog[2][1] = 0 - input.analog[2][1]; + + /* Map mouse buttons to player #1 inputs */ + if(mouse_b & 4) input.pad[joynum] |= INPUT_C; + if(mouse_b & 1) input.pad[joynum] |= INPUT_B; + if(mouse_b & 2) input.pad[joynum] |= INPUT_A; + if(key[KEY_F]) input.pad[joynum] |= INPUT_START; + } else if (system_hw == SYSTEM_PICO) { - /* Poll mouse if necessary */ - if(mouse_needs_poll() == TRUE) - poll_mouse(); + /* Poll mouse if necessary */ + if(mouse_needs_poll() == TRUE) + poll_mouse(); - /* Calculate X Y axis values */ - input.analog[0][0] = 0x3c + (mouse_x * (0x17c-0x03c+1)) / SCREEN_W; - input.analog[0][1] = 0x1fc + (mouse_y * (0x2f7-0x1fc+1)) / SCREEN_H; + /* Calculate X axis value */ + input.analog[0][0] = 0x3c + (mouse_x * (0x17c - 0x3c + 1) / SCREEN_W); - /* Map mouse buttons to player #1 inputs */ - if(mouse_b & 4) input.pad[joynum] |= INPUT_START; - if(mouse_b & 2) input.pad[joynum] |= INPUT_A; - if(mouse_b & 1) input.pad[joynum] |= INPUT_B; + /* Calculate Y axis value */ + input.analog[0][1] = 0x1fc + (mouse_y* (0x3f3 - 0x1fc + 1) / SCREEN_H); + + /* Map mouse buttons to player #1 inputs */ + if(mouse_b & 2) input.pad[0] |= INPUT_B; + if(mouse_b & 1) input.pad[0] |= INPUT_A; + if(mouse_b & 4) pico_current++; + if (pico_current > 6) pico_current = 0; } - if(check_key(KEY_F1)) frame_skip = 1; - if(check_key(KEY_F2)) frame_skip = 2; - if(check_key(KEY_F3)) frame_skip = 3; - if(check_key(KEY_F4)) frame_skip = 4; + + if(check_key(KEY_F1)) frame_skip = 1; + if(check_key(KEY_F2)) frame_skip = 2; + if(check_key(KEY_F3)) frame_skip = 3; + if(check_key(KEY_F4)) frame_skip = 4; if(check_key(KEY_F5)) log_error ^= 1; if(check_key(KEY_F6)) debug_on ^= 1; @@ -315,11 +364,7 @@ void dos_update_input(void) f = fopen("game.gpz","r+b"); if (f) { - int len = 0; - fread(&len, 4, 1, f); - fclose(f); - fopen("game.gpz","r+b"); - fread(&buf, len+4, 1, f); + fread(&buf, 0x23000, 1, f); state_load(buf); fclose(f); } @@ -330,18 +375,22 @@ void dos_update_input(void) f = fopen("game.gpz","w+b"); if (f) { - int size = state_save(buf); - fwrite(&buf, size, 1, f); + state_save(buf); + fwrite(&buf, 0x23000, 1, f); fclose(f); } } - if(check_key(KEY_F9)) - { - vdp_pal ^= 1; - system_init(); - audio_init(option.sndrate); - fm_restore(); + if(check_key(KEY_F9)) + { + vdp_pal ^= 1; + + /* reinitialize timings */ + system_init (); + audio_init(48000); + fm_restore(); + + /* reinitialize HVC tables */ vctab = (vdp_pal) ? ((reg[1] & 8) ? vc_pal_240 : vc_pal_224) : vc_ntsc_224; hctab = (reg[12] & 1) ? cycle2hc40 : cycle2hc32; @@ -349,30 +398,13 @@ void dos_update_input(void) bitmap.viewport.x = config.overscan ? ((reg[12] & 1) ? 16 : 12) : 0; bitmap.viewport.y = config.overscan ? (((reg[1] & 8) ? 0 : 8) + (vdp_pal ? 24 : 0)) : 0; bitmap.viewport.changed = 1; - } - - if(check_key(KEY_F10)) - system_reset(); - - if(check_key(KEY_F11)) - { - joynum ++; - if (joynum > MAX_DEVICES - 1) joynum = 0; - while (input.dev[joynum] == NO_DEVICE) - { - joynum ++; - if (joynum > MAX_DEVICES - 1) joynum = 0; - } - } - - if(check_key(KEY_F12)) - { - input.x_offset ++; - if (input.x_offset > 0xff) input.x_offset = 0; } + if(check_key(KEY_F10)) + { + system_reset(); + } - if(check_key(KEY_TAB)) - resetline = (int) ((double) (lines_per_frame - 1) * rand() / (RAND_MAX + 1.0)); + if(check_key(KEY_TAB)) set_softreset(); } void dos_update_audio(void) @@ -470,7 +502,7 @@ void dos_update_video(void) }*/ - msg_print(2, 2, "%d fps", frame_rate); + msg_print(2, 2, "offset = 0x%x", hc_latch/*frame_rate*/); if(option.scanlines) { diff --git a/source/unused/dos/dos.h b/source/unused/dos/dos.h index a94fc72..423c8b5 100644 --- a/source/unused/dos/dos.h +++ b/source/unused/dos/dos.h @@ -17,8 +17,26 @@ void make_vdp_palette(void); void dos_change_mode(void); int check_key(int code); +#define update_input() dos_update_input() +#define MAX_INPUTS 8 + +/* options */ +extern uint8 overscan; +extern uint8 use_480i; +extern uint8 FM_GENS; +extern uint8 hq_fm; +extern uint8 ssg_enabled; +extern double psg_preamp; +extern double fm_preamp; +extern uint8 boost; +extern uint8 region_detect; +extern uint8 sys_type[2]; +extern uint8 force_dtack; +extern uint8 dmatiming; +extern uint8 vdptiming; + extern uint8 debug_on; extern uint8 log_error; -extern int frame_count; + #endif /* _DOS_H_ */ diff --git a/source/unused/dos/error.c b/source/unused/dos/error.c index 4913848..27eae74 100644 --- a/source/unused/dos/error.c +++ b/source/unused/dos/error.c @@ -11,20 +11,20 @@ struct { void error_init(void) { - error_log = fopen("error.log","w"); + error_log = fopen("error.log","w"); } void error_shutdown(void) { - if(error_log) fclose(error_log); + if(error_log) fclose(error_log); } void error(char *format, ...) { if (!log_error) return; va_list ap; - va_start(ap, format); - if(error_log) vfprintf(error_log, format, ap); - va_end(ap); + va_start(ap, format); + if(error_log) vfprintf(error_log, format, ap); + va_end(ap); } diff --git a/source/unused/fileio.c b/source/unused/dos/fileio.c similarity index 100% rename from source/unused/fileio.c rename to source/unused/dos/fileio.c diff --git a/source/unused/fileio.h b/source/unused/dos/fileio.h similarity index 100% rename from source/unused/fileio.h rename to source/unused/dos/fileio.h diff --git a/source/unused/dos/osd.h b/source/unused/dos/osd.h index 3b76d8c..991b60a 100644 --- a/source/unused/dos/osd.h +++ b/source/unused/dos/osd.h @@ -17,6 +17,5 @@ #include "unzip.h" #include "fileio.h" -#define update_input() dos_update_input() - +volatile int frame_count; #endif /* _OSD_H_ */ diff --git a/source/unused/dos/readme-djgpp.txt b/source/unused/dos/readme-djgpp.txt new file mode 100644 index 0000000..4af1e41 --- /dev/null +++ b/source/unused/dos/readme-djgpp.txt @@ -0,0 +1,3 @@ +To be compiled with DJGPP. +You will also need to install Allegro and Seal libraries. +Zlib is required for zipped rom support. \ No newline at end of file diff --git a/source/unused/make.bat b/source/unused/make.bat deleted file mode 100644 index 62b0373..0000000 --- a/source/unused/make.bat +++ /dev/null @@ -1 +0,0 @@ -@make.exe -f makefile.mgw %1 diff --git a/source/unused/makefile.mgw b/source/unused/makefile.mgw deleted file mode 100644 index b2782f2..0000000 --- a/source/unused/makefile.mgw +++ /dev/null @@ -1,107 +0,0 @@ -# Genesis Plus - Sega Mega Drive emulator -# (c) 1999, 2000, 2001, 2002, 2003 Charles MacDonald - -# -DLSB_FIRST - Leave undefined for big-endian processors. -# -DDEBUG - Enable debugging code -# -DX86_ASM - Enable inline x86 assembly code in Z80 emulator - -CC = gcc -AS = nasm -f coff -LDFLAGS = -FLAGS = -I. -Icpu -Im68k -Iwin -Isound -Icart_hw -Icart_hw\svp \ - -Ic:/SDL/include/SDL \ - -Werror -Wall \ - -DLSB_FIRST -DX86_ASM \ - -O6 -march=pentium -fomit-frame-pointer - -LIBS = -lz -lm -lmingw32 -Ld:/sdl/lib -lSDLmain -lSDL obj/m68k.oa - -OBJ = obj/z80.oa \ - obj/genesis.o \ - obj/vdp.o \ - obj/render.o \ - obj/system.o \ - obj/io.o \ - obj/input.o \ - obj/mem68k.o \ - obj/memz80.o \ - obj/membnk.o \ - obj/memvdp.o \ - obj/state.o - -OBJ += obj/sound.o \ - obj/fm.o \ - obj/sn76489.o \ - obj/ym2612.o - -OBJ += obj/sram.o \ - obj/eeprom.o \ - obj/svp.o \ - obj/ssp16.o \ - obj/cart_hw.o - -OBJ += obj/main.o \ - obj/error.o \ - obj/fileio.o \ - obj/unzip.o \ - obj/loadrom.o - -EXE = gen.exe - -all : $(EXE) - -$(EXE) : $(OBJ) shared.h - $(CC) -o $(EXE) $(OBJ) $(LIBS) $(LDFLAGS) - -obj/%.oa : cpu/%.c cpu/%.h - $(CC) -c $< -o $@ $(FLAGS) - -obj/%.o : %.c %.h - $(CC) -c $< -o $@ $(FLAGS) - -obj/%.o : win/%.s - $(AS) $< -o $@ - -obj/%.o : sound/%.c sound/%.h - $(CC) -c $< -o $@ $(FLAGS) - -obj/%.o : cpu/%.c cpu/%.h - $(CC) -c $< -o $@ $(FLAGS) - -obj/%.o : win/%.c win/%.h - $(CC) -c $< -o $@ $(FLAGS) - -obj/%.o : cart_hw/%.c cart_hw/%.h - $(CC) -c $< -o $@ $(FLAGS) - -obj/%.o : cart_hw/svp/%.c - $(CC) -c $< -o $@ $(FLAGS) - -obj/%.o : cart_hw/svp/%.c cart_hw/svp/%.h - $(CC) -c $< -o $@ $(FLAGS) - - -pack : - strip $(EXE) - upx -1 $(EXE) - -clean : - rm -f obj/*.o - rm -f *.bak - rm -f *.exe - rm -f *.log - rm -f *.wav - rm -f *.zip -cleancpu : - rm -f obj/z80.oa - -makedir : - mkdir obj - -archive: - pk -add -max -excl=bak -excl=out \ - -excl=test -excl=obj mdsrc.zip -dir=current - -# -# end of makefile -# diff --git a/source/unused/unzip.c b/source/unused/unzip.c deleted file mode 100644 index 6d740a1..0000000 --- a/source/unused/unzip.c +++ /dev/null @@ -1,1301 +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; -{ -/* int err=UNZ_OK; */ - 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/source/unused/unzip.h b/source/unused/unzip.h deleted file mode 100644 index c7ba82a..0000000 --- a/source/unused/unzip.h +++ /dev/null @@ -1,274 +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/source/unused/win/Makefile b/source/unused/win/Makefile new file mode 100644 index 0000000..304e977 --- /dev/null +++ b/source/unused/win/Makefile @@ -0,0 +1,105 @@ + +# Makefile for genplus SDL +# +# (c) 1999, 2000, 2001, 2002, 2003 Charles MacDonald +# modified by Eke-Eke +# +# Defines : +# LSB_FIRST : for little endian systems. +# X86_ASM : enable x86 assembly optimizations + +NAME = gp_sdl + +CC = gcc +CFLAGS = `sdl-config --cflags` -O6 -march=i686 -fomit-frame-pointer +DEFINES = -DLSB_FIRST -DX86_ASM +INCLUDES = -I. -I.. -I../cpu -I../m68k -I../dos -I../sound -I../sound/SRC -I../cart_hw -I../cart_hw/svp +LIBS = `sdl-config --libs` -lz -lm + +OBJECTS = obj/z80.o + +OBJECTS += obj/m68kcpu.o \ + obj/m68kops.o + + +OBJECTS += obj/genesis.o \ + obj/vdp.o \ + obj/render.o \ + obj/system.o \ + obj/gen_io.o \ + obj/gen_input.o \ + obj/mem68k.o \ + obj/memz80.o \ + obj/membnk.o \ + obj/memvdp.o \ + obj/state.o + +OBJECTS += obj/sound.o \ + obj/fm.o \ + obj/sn76489.o \ + obj/ym2612.o + +OBJECTS += obj/samplerate.o \ + obj/src_linear.o \ + obj/src_sinc.o \ + obj/src_zoh.o \ + + +OBJECTS += obj/sram.o \ + obj/eeprom.o \ + obj/svp.o \ + obj/ssp16.o \ + obj/cart_hw.o + +OBJECTS += obj/main.o \ + obj/config.o \ + obj/error.o \ + obj/unzip.o \ + obj/fileio.o \ + obj/loadrom.o + + +all: $(NAME) + +$(NAME): $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $@ + +obj/%.o : ../%.c ../%.h + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ + +obj/%.o : ../asm/%.s + $(AS) $< -o $@ + +obj/%.o : ../sound/%.c ../sound/%.h + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ +obj/%.o : ../sound/%.c + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ + +obj/%.o : ../sound/SRC/%.c ../sound/SRC/%.h + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ +obj/%.o : ../sound/SRC/%.c + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ + +obj/%.o : ../cart_hw/%.c ../cart_hw/%.h + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ + +obj/%.o : ../cart_hw/svp/%.c + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ +obj/%.o : ../cart_hw/svp/%.c ../cart_hw/svp/%.h + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ + +obj/%.o : ../cpu/%.c ../cpu/%.h + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ + +obj/%.o : ../m68k/%.c ../m68k/%.h + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ + +obj/%.o : ./%.c ./%.h + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@ + +pack : + strip $(EXE) + upx -1 $(EXE) + +clean: + rm -f $(OBJECTS) $(NAME) diff --git a/source/unused/win/config.c b/source/unused/win/config.c new file mode 100644 index 0000000..e22afae --- /dev/null +++ b/source/unused/win/config.c @@ -0,0 +1,43 @@ + +#include "osd.h" + +#define CONFIG_VERSION "GENPLUS 1.2.1 " + +t_config config; + + +void set_config_defaults(void) +{ + /* version TAG */ + strncpy(config.version,CONFIG_VERSION,15); + + /* sound options */ + config.psg_preamp = 1.5; + config.fm_preamp = 1.0; + config.boost = 1; + config.filter = 0; + + config.hq_fm = 1; + config.fm_core = 0; + + /* system options */ + config.freeze_auto = -1; + config.sram_auto = -1; + config.region_detect = 0; + config.force_dtack = 0; + config.bios_enabled = 0; + + /* display options */ + config.xshift = 0; + config.yshift = 0; + config.xscale = 0; + config.yscale = 0; + config.aspect = 1; + config.overscan = 1; + config.render = 0; + + /* controllers options */ + config.gun_cursor = 1; + config.invert_mouse = 0; +} + diff --git a/source/unused/win/config.h b/source/unused/win/config.h new file mode 100644 index 0000000..165f922 --- /dev/null +++ b/source/unused/win/config.h @@ -0,0 +1,39 @@ + +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +/**************************************************************************** + * Config Option + * + ****************************************************************************/ +typedef struct +{ + char version[15]; + double psg_preamp; + double fm_preamp; + uint8 boost; + uint8 filter; + uint8 hq_fm; + uint8 fm_core; + int8 sram_auto; + int8 freeze_auto; + uint8 region_detect; + uint8 force_dtack; + uint8 bios_enabled; + int16 xshift; + int16 yshift; + int16 xscale; + int16 yscale; + uint8 tv_mode; + uint8 aspect; + uint8 overscan; + uint8 render; + uint8 gun_cursor; + uint8 invert_mouse; +} t_config; + +/* Global variables */ +extern t_config config; + +#endif /* _CONFIG_H_ */ + diff --git a/source/unused/win/error.c b/source/unused/win/error.c index 298d4e1..27eae74 100644 --- a/source/unused/win/error.c +++ b/source/unused/win/error.c @@ -1,9 +1,5 @@ -/* - error.c -- - Error logging -*/ -#include "shared.h" +#include "osd.h" FILE *error_log; @@ -15,25 +11,20 @@ struct { void error_init(void) { -#ifdef DEBUG - error_log = fopen("error.log","w"); -#endif + error_log = fopen("error.log","w"); } void error_shutdown(void) { -#ifdef DEBUG - if(error_log) fclose(error_log); -#endif + if(error_log) fclose(error_log); } void error(char *format, ...) { -#ifdef DEBUG - va_list ap; - va_start(ap, format); - if(error_log) vfprintf(error_log, format, ap); - va_end(ap); -#endif + if (!log_error) return; + va_list ap; + va_start(ap, format); + if(error_log) vfprintf(error_log, format, ap); + va_end(ap); } diff --git a/source/unused/win/fileio.c b/source/unused/win/fileio.c new file mode 100644 index 0000000..6c4b169 --- /dev/null +++ b/source/unused/win/fileio.c @@ -0,0 +1,151 @@ +#include "shared.h" + +/* + Load a normal file, or ZIP/GZ archive. + Returns NULL if an error occured. +*/ +uint8 *load_archive(char *filename, int *file_size) +{ + int size = 0; + uint8 *buf = NULL; + + if(check_zip(filename)) + { + unzFile *fd = NULL; + unz_file_info info; + int ret = 0; + + /* Attempt to open the archive */ + fd = unzOpen(filename); + if(!fd) return (NULL); + + /* Go to first file in archive */ + ret = unzGoToFirstFile(fd); + if(ret != UNZ_OK) + { + unzClose(fd); + return (NULL); + } + + ret = unzGetCurrentFileInfo(fd, &info, NULL, 0, NULL, 0, NULL, 0); + if(ret != UNZ_OK) + { + unzClose(fd); + return (NULL); + } + + /* Open the file for reading */ + ret = unzOpenCurrentFile(fd); + if(ret != UNZ_OK) + { + unzClose(fd); + return (NULL); + } + + /* Allocate file data buffer */ + size = info.uncompressed_size; + buf = malloc(size); + if(!buf) + { + unzClose(fd); + return (NULL); + } + + /* Read (decompress) the file */ + ret = unzReadCurrentFile(fd, buf, info.uncompressed_size); + if(ret != info.uncompressed_size) + { + free(buf); + unzCloseCurrentFile(fd); + unzClose(fd); + return (NULL); + } + + /* Close the current file */ + ret = unzCloseCurrentFile(fd); + if(ret != UNZ_OK) + { + free(buf); + unzClose(fd); + return (NULL); + } + + /* Close the archive */ + ret = unzClose(fd); + if(ret != UNZ_OK) + { + free(buf); + return (NULL); + } + + /* Update file size and return pointer to file data */ + *file_size = size; + return (buf); + } + else + { + gzFile *gd = NULL; + + /* Open file */ + gd = gzopen(filename, "rb"); + if(!gd) return (0); + + /* Get file size */ + size = gzsize(gd); + + /* Allocate file data buffer */ + buf = malloc(size); + if(!buf) + { + gzclose(gd); + return (0); + } + + /* Read file data */ + gzread(gd, buf, size); + + /* Close file */ + gzclose(gd); + + /* Update file size and return pointer to file data */ + *file_size = size; + return (buf); + } +} + + +/* + Verifies if a file is a ZIP archive or not. + Returns: 1= ZIP archive, 0= not a ZIP archive +*/ +int check_zip(char *filename) +{ + uint8 buf[2]; + FILE *fd = NULL; + fd = fopen(filename, "rb"); + if(!fd) return (0); + fread(buf, 2, 1, fd); + fclose(fd); + if(memcmp(buf, "PK", 2) == 0) return (1); + return (0); +} + + +/* + Returns the size of a GZ compressed file. +*/ +int gzsize(gzFile *gd) +{ + #define CHUNKSIZE (0x10000) + int size = 0, length = 0; + unsigned char buffer[CHUNKSIZE]; + gzrewind(gd); + do { + size = gzread(gd, buffer, CHUNKSIZE); + if(size <= 0) break; + length += size; + } while (!gzeof(gd)); + gzrewind(gd); + return (length); + #undef CHUNKSIZE +} diff --git a/source/unused/win/fileio.h b/source/unused/win/fileio.h new file mode 100644 index 0000000..b99bfc2 --- /dev/null +++ b/source/unused/win/fileio.h @@ -0,0 +1,14 @@ +#ifndef _FILEIO_H_ +#define _FILEIO_H_ + +/* Global variables */ +extern int cart_size; +extern char cart_name[0x100]; + +/* Function prototypes */ +uint8 *load_archive(char *filename, int *file_size); +int load_cart(char *filename); +int check_zip(char *filename); +int gzsize(gzFile *gd); + +#endif /* _FILEIO_H_ */ diff --git a/source/unused/win/main.c b/source/unused/win/main.c index af4d896..4770535 100644 --- a/source/unused/win/main.c +++ b/source/unused/win/main.c @@ -11,18 +11,6 @@ int frame_count = 0; int update_input(void); unsigned char *keystate; -/* Options default */ -uint8 overscan = 1; -uint8 use_480i = 1; -uint8 FM_GENS = 1; -uint8 hq_fm = 1; -double psg_preamp = 0.5; -double fm_preamp = 1.0; -uint8 boost = 1; -uint8 region_detect = 0; -uint8 sys_type[2] = {0,0}; -uint8 force_dtack = 0; - uint8 log_error = 1; uint8 debug_on = 0; @@ -35,7 +23,7 @@ Uint32 fps_callback(Uint32 interval) { int fps = frame_count; char caption[32]; - sprintf(caption, "Genesis Plus/SDL FPS=%d", fps); + sprintf(caption, "Genesis Plus/SDL FPS=%d", fps); SDL_WM_SetCaption(caption, NULL); frame_count = 0; } @@ -47,23 +35,25 @@ int main (int argc, char **argv) { int running = 1; - SDL_Rect viewport, src; - SDL_Surface *bmp, *screen; - SDL_Event event; + SDL_Rect viewport, src; + SDL_Surface *bmp, *screen; + SDL_Event event; - error_init(); + error_init(); - /* Print help if no game specified */ + /* Print help if no game specified */ if(argc < 2) { char caption[256]; - sprintf(caption, "Genesis Plus\nby Charles MacDonald\nWWW: http://cgfm2.emuviews.com\nusage: %s gamename\n", argv[0]); - MessageBox(NULL, caption, "Information", 0); + sprintf(caption, "Genesis Plus\nby Charles MacDonald\nWWW: http://cgfm2.emuviews.com\nusage: %s gamename\n", argv[0]); + MessageBox(NULL, caption, "Information", 0); exit(1); } /* Load game */ - if(!load_rom(argv[1])) + cart_rom = malloc(0xA00000); + memset(cart_rom, 0, 0xA00000); + if(!load_rom(argv[1])) { char caption[256]; sprintf(caption, "Error loading file `%s'.", argv[1]); @@ -71,52 +61,77 @@ int main (int argc, char **argv) exit(1); } - viewport.x = 0; - viewport.y = 0; - viewport.w = 256; - viewport.h = 224; + /* load SRAM */ + FILE *f = fopen("./game.srm", "rb"); + if (f!=NULL) + { + fread(&sram.sram,0x10000,1, f); + fclose(f); + } - src.x = 32; - src.y = 0; - src.w = viewport.w; - src.h = viewport.h; + /* load BIOS */ + memset(bios_rom, 0, sizeof(bios_rom)); + f = fopen("./BIOS.bin", "rb"); + if (f!=NULL) + { + fread(&bios_rom, 0x800,1,f); + fclose(f); + int i; + for(i = 0; i < 0x800; i += 2) + { + uint8 temp = bios_rom[i]; + bios_rom[i] = bios_rom[i+1]; + bios_rom[i+1] = temp; + } + config.bios_enabled = 3; + } + else config.bios_enabled = 0; - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) - { - exit(1); - } - SDL_WM_SetCaption("Genesis Plus/SDL", NULL); + /* initialize SDL */ + viewport.w = 640; + viewport.h = 480; + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) + { + exit(1); + } + SDL_WM_SetCaption("Genesis Plus/SDL", NULL); + screen = SDL_SetVideoMode(viewport.w, viewport.h, 16, SDL_HWSURFACE); + bmp = SDL_CreateRGBSurface(SDL_SWSURFACE, 1024, 512, 16, 0xF800, 0x07E0, 0x001F, 0x0000); - screen = SDL_SetVideoMode(viewport.w, viewport.h, 16, SDL_SWSURFACE); - viewport.x = 0; - viewport.y = 0; + /* initialize Genesis screen */ + memset(&bitmap, 0, sizeof(t_bitmap)); + bitmap.width = 1024; + bitmap.height = 512; + bitmap.depth = 16; + bitmap.granularity = 2; + bitmap.pitch = (bitmap.width * bitmap.granularity); + bitmap.data = (unsigned char *)bmp->pixels; + bitmap.viewport.w = 256; + bitmap.viewport.h = 224; + bitmap.viewport.x = 0; + bitmap.viewport.y = 0; + bitmap.remap = 1; - bmp = SDL_CreateRGBSurface(SDL_SWSURFACE, 1024, 512, 16, 0xF800, 0x07E0, 0x001F, 0x0000); + /* default config */ + set_config_defaults(); + input.system[0] = SYSTEM_GAMEPAD; + input.system[1] = SYSTEM_GAMEPAD; + + /* initialize emulation */ + int buf_len = (44100 * 4) / vdp_rate; + snd.buffer[0] = malloc (buf_len/2); + snd.buffer[1] = malloc (buf_len/2); + memset (snd.buffer[0], 0, buf_len/2); + memset (snd.buffer[1], 0, buf_len/2); + system_init(); + audio_init(44100); + system_reset(); - - memset(&bitmap, 0, sizeof(t_bitmap)); - bitmap.width = 1024; - bitmap.height = 512; - bitmap.depth = 16; - bitmap.granularity = 2; - bitmap.pitch = (bitmap.width * bitmap.granularity); - bitmap.data = (unsigned char *)bmp->pixels; - bitmap.viewport.w = 256; - bitmap.viewport.h = 224; - bitmap.viewport.x = 0x20; - bitmap.viewport.y = 0x00; - bitmap.remap = 1; - - system_init(); - system_reset(); - - SDL_SetTimer(1000/60, fps_callback); - + /* emulation loop */ + SDL_SetTimer(1000/60, fps_callback); while(running) { - running = update_input(); - while (SDL_PollEvent(&event)) { switch(event.type) @@ -141,78 +156,75 @@ int main (int argc, char **argv) { frame_count++; - update_input(); + if(!system_frame(0)) + system_reset(); - if(!system_frame(0)) - system_reset(); - - if(bitmap.viewport.changed) - { - bitmap.viewport.changed = 0; - src.w = bitmap.viewport.w; - src.h = bitmap.viewport.h; - viewport.w = bitmap.viewport.w; - viewport.h = bitmap.viewport.h; - screen = SDL_SetVideoMode(bitmap.viewport.w, bitmap.viewport.h, 16, SDL_SWSURFACE); - } - - SDL_BlitSurface(bmp, &src, screen, &viewport); - SDL_UpdateRect(screen, viewport.x, viewport.y, viewport.w, viewport.h); - } + if(bitmap.viewport.changed) + { + bitmap.viewport.changed = 0; + src.w = (bitmap.viewport.w + 2 * bitmap.viewport.x); + src.h = (bitmap.viewport.h + 2 * bitmap.viewport.y) << (interlaced ? 1:0); + viewport.w = src.w; + viewport.h = src.h; + viewport.x = (640 - viewport.w) / 2; + viewport.y = (480 - viewport.h) / 2; + //screen = SDL_SetVideoMode(bitmap.viewport.w, bitmap.viewport.h, 16, SDL_SWSURFACE); + SDL_BlitSurface(bmp, &src, screen, &viewport); + SDL_UpdateRect(screen, viewport.x, viewport.y, viewport.w, viewport.h); + } } + } + + system_shutdown(); + SDL_Quit(); + error_shutdown(); - system_shutdown(); - SDL_Quit(); - error_shutdown(); - - return 0; + return 0; } /* Check if a key is pressed */ int check_key(int code) { - static char lastbuf[0x100] = {0}; + static char lastbuf[0x100] = {0}; - if((!keystate[code]) && (lastbuf[code] == 1)) - lastbuf[code] = 0; + if((!keystate[code]) && (lastbuf[code] == 1)) + lastbuf[code] = 0; - if((keystate[code]) && (lastbuf[code] == 0)) - { - lastbuf[code] = 1; - return (1); - } + if((keystate[code]) && (lastbuf[code] == 0)) + { + lastbuf[code] = 1; + return (1); + } - return (0); + return (0); } int update_input(void) { - int running = 1; + int running = 1; - keystate = SDL_GetKeyState(NULL); + keystate = SDL_GetKeyState(NULL); - memset(&input, 0, sizeof(t_input)); - if(keystate[SDLK_UP]) input.pad[0] |= INPUT_UP; - else - if(keystate[SDLK_DOWN]) input.pad[0] |= INPUT_DOWN; - if(keystate[SDLK_LEFT]) input.pad[0] |= INPUT_LEFT; - else - if(keystate[SDLK_RIGHT]) input.pad[0] |= INPUT_RIGHT; + memset(&input, 0, sizeof(t_input)); + if(keystate[SDLK_UP]) input.pad[0] |= INPUT_UP; + else + if(keystate[SDLK_DOWN]) input.pad[0] |= INPUT_DOWN; + if(keystate[SDLK_LEFT]) input.pad[0] |= INPUT_LEFT; + else + if(keystate[SDLK_RIGHT]) input.pad[0] |= INPUT_RIGHT; - if(keystate[SDLK_a]) input.pad[0] |= INPUT_A; - if(keystate[SDLK_s]) input.pad[0] |= INPUT_B; - if(keystate[SDLK_d]) input.pad[0] |= INPUT_C; - if(keystate[SDLK_f]) input.pad[0] |= INPUT_START; - if(keystate[SDLK_z]) input.pad[0] |= INPUT_X; - if(keystate[SDLK_x]) input.pad[0] |= INPUT_Y; - if(keystate[SDLK_c]) input.pad[0] |= INPUT_Z; - if(keystate[SDLK_v]) input.pad[0] |= INPUT_MODE; + if(keystate[SDLK_a]) input.pad[0] |= INPUT_A; + if(keystate[SDLK_s]) input.pad[0] |= INPUT_B; + if(keystate[SDLK_d]) input.pad[0] |= INPUT_C; + if(keystate[SDLK_f]) input.pad[0] |= INPUT_START; + if(keystate[SDLK_z]) input.pad[0] |= INPUT_X; + if(keystate[SDLK_x]) input.pad[0] |= INPUT_Y; + if(keystate[SDLK_c]) input.pad[0] |= INPUT_Z; + if(keystate[SDLK_v]) input.pad[0] |= INPUT_MODE; - if(keystate[SDLK_TAB]) system_reset(); + if(keystate[SDLK_TAB]) system_reset(); - if(keystate[SDLK_ESCAPE]) running = 0; - return (running); + if(keystate[SDLK_ESCAPE]) running = 0; + return (running); } - - diff --git a/source/unused/win/main.h b/source/unused/win/main.h index 164d9b8..47c32b0 100644 --- a/source/unused/win/main.h +++ b/source/unused/win/main.h @@ -2,17 +2,8 @@ #ifndef _MAIN_H_ #define _MAIN_H_ -/* options */ -extern uint8 overscan; -extern uint8 use_480i; -extern uint8 FM_GENS; -extern uint8 hq_fm; -extern double psg_preamp; -extern double fm_preamp; -extern uint8 boost; -extern uint8 region_detect; -extern uint8 sys_type[2]; -extern uint8 force_dtack; +#define MAX_INPUTS 8 + extern uint8 debug_on; extern uint8 log_error; diff --git a/source/unused/win/osd.h b/source/unused/win/osd.h index 233d135..572756b 100644 --- a/source/unused/win/osd.h +++ b/source/unused/win/osd.h @@ -8,12 +8,13 @@ #include #include -#include "SDL.h" +#include #include -#include "error.h" #include "shared.h" #include "main.h" +#include "config.h" +#include "error.h" #include "unzip.h" #include "fileio.h" diff --git a/source/unused/win/readme-sdl.txt b/source/unused/win/readme-sdl.txt new file mode 100644 index 0000000..7d7fb0f --- /dev/null +++ b/source/unused/win/readme-sdl.txt @@ -0,0 +1,3 @@ +To be compiled with MinGW. +You will also need to install SDL library +Zlib is required for zipped rom support. \ No newline at end of file diff --git a/source/unzip.c b/source/unzip.c index 6d740a1..cb68299 100644 --- a/source/unzip.c +++ b/source/unzip.c @@ -161,7 +161,7 @@ local int unzlocal_getShort (fin,pX) uLong *pX; { uLong x ; - int i; + int i = 0; int err; err = unzlocal_getByte(fin,&i); @@ -183,7 +183,7 @@ local int unzlocal_getLong (fin,pX) uLong *pX; { uLong x ; - int i; + int i = 0; int err; err = unzlocal_getByte(fin,&i);