fixed bug with sound output, fixed vdp latency during VBLANK, improved SDL/DOS ports

This commit is contained in:
ekeeke31 2008-08-22 15:58:49 +00:00
parent 6749058dad
commit fb9c8eeb19
25 changed files with 989 additions and 189 deletions

340
source/LICENSE Normal file
View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
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.
<signature of Ty Coon>, 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.

89
source/PORTING Normal file
View File

@ -0,0 +1,89 @@
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.

View File

@ -4,7 +4,7 @@
#include <fat.h>
#include <sys/dir.h>
#define CONFIG_VERSION "GENPLUS 1.2.1 "
#define CONFIG_VERSION "GENPLUS 1.2.2 "
t_config config;
@ -54,6 +54,7 @@ void set_config_defaults(void)
config.fm_preamp = 1.0;
config.boost = 1;
config.hq_fm = 1;
config.filter = 1;
config.fm_core = 0;
/* system options */

View File

@ -14,6 +14,7 @@ typedef struct
uint8 boost;
uint8 filter;
uint8 hq_fm;
uint8 filter;
uint8 fm_core;
int8 sram_auto;
int8 freeze_auto;

View File

@ -134,8 +134,8 @@ void soundmenu ()
int ret;
int quit = 0;
int prevmenu = menu;
int count = 5;
char items[5][20];
int count = 6;
char items[6][20];
strcpy (menutitle, "Press B to return");
@ -145,24 +145,25 @@ void soundmenu ()
sprintf (items[0], "PSG Volume: %1.2f", config.psg_preamp);
sprintf (items[1], "FM Volume: %1.2f", config.fm_preamp);
sprintf (items[2], "Volume Boost: %dX", config.boost);
if (config.hq_fm == 0) sprintf (items[3], "HQ YM2612: OFF");
sprintf (items[3], "LowPass Filter: %s", config.filter ? " ON":"OFF");
if (config.hq_fm == 0) sprintf (items[4], "HQ YM2612: OFF");
else if (config.fm_core)
{
/* GENS core only got linear resampling */
sprintf (items[3], "HQ YM2612: LINEAR");
sprintf (items[4], "HQ YM2612: LINEAR");
}
else
{
/* MAME core uses libsamplerate */
if (config.hq_fm == 1) sprintf (items[3], "HQ YM2612: LINEAR");
else if (config.hq_fm == 2) sprintf (items[3], "HQ YM2612: LOW");
else if (config.hq_fm == 3) sprintf (items[3], "HQ YM2612: FAST");
else if (config.hq_fm == 4) sprintf (items[3], "HQ YM2612: MEDIUM");
if (config.hq_fm == 1) sprintf (items[4], "HQ YM2612: LINEAR");
else if (config.hq_fm == 2) sprintf (items[4], "HQ YM2612: LOW");
else if (config.hq_fm == 3) sprintf (items[4], "HQ YM2612: FAST");
else if (config.hq_fm == 4) sprintf (items[4], "HQ YM2612: MEDIUM");
#ifdef USE_SINC_BEST
else if (config.hq_fm == 5) sprintf (items[3], "HQ YM2612: BEST");
else if (config.hq_fm == 5) sprintf (items[4], "HQ YM2612: BEST");
#endif
}
sprintf (items[4], "FM core: %s", config.fm_core ? "GENS" : "MAME");
sprintf (items[5], "FM core: %s", config.fm_core ? "GENS" : "MAME");
ret = domenu (&items[0], count, 1);
switch (ret)
@ -189,6 +190,10 @@ void soundmenu ()
break;
case 3:
config.filter ^= 1;
break;
case 4:
#ifdef USE_SINC_BEST
config.hq_fm = (config.hq_fm + 1) % (config.fm_core ? 2 : 6);
#else
@ -201,7 +206,7 @@ void soundmenu ()
}
break;
case 4:
case 5:
config.fm_core ^= 1;
config.psg_preamp = config.fm_core ? 2.5 : 1.5;
config.fm_preamp = 1.0;

View File

@ -177,7 +177,11 @@ int system_frame (int do_skip)
/* increment frame counter */
frame_cnt ++;
if (!gen_running) return 0;
if (!gen_running)
{
update_input();
return 0;
}
/* Clear VBLANK & DMA BUSY flags */
status &= 0xFFF5;
@ -367,8 +371,8 @@ static void audio_update (void)
}
/* boost volume if asked*/
l = ll * boost;
r = rr * boost;
l = l * boost;
r = r * boost;
/* clipping */
if (l > 32767) l = 32767;

28
source/unused/CHANGELOG Normal file
View File

@ -0,0 +1,28 @@
[05/25/03]
- Fixed a typo that made Z80 banked access to the VDP registers always fail.
[05/17/03]
- Modified the rendering code to handle unaligned longword access to memory.
[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.

122
source/unused/README Normal file
View File

@ -0,0 +1,122 @@
----------------------------------------------------------------------------
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 <x> <y> set the display resolution.
-vdriver <n> specify video driver.
-depth <n> 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 <n> specify sound rate. (8000, 11025, 22050, 44100)
-sndcard <n> specify sound card. (0-7)
-swap swap left and right stereo output.
-joy <s> 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)

79
source/unused/TODO Normal file
View File

@ -0,0 +1,79 @@
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

View File

@ -12,20 +12,20 @@
CC = gcc
AS = nasm -f coff
LDFLAGS =
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
FLAGS = -I. -I.. -I../z80 -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 -lm
OBJ = obj/z80.o
OBJ = obj/z80.o
OBJ += obj/m68kcpu.o \
OBJ += obj/m68kcpu.o \
obj/m68kops.o
OBJ += obj/genesis.o \
OBJ += obj/genesis.o \
obj/vdp.o \
obj/render.o \
obj/system.o \
@ -37,7 +37,7 @@ OBJ += obj/genesis.o \
obj/memvdp.o \
obj/state.o
OBJ += obj/sound.o \
OBJ += obj/sound.o \
obj/fm.o \
obj/sn76489.o \
obj/ym2612.o
@ -48,7 +48,7 @@ OBJ += obj/samplerate.o \
obj/src_sinc.o \
obj/src_zoh.o \
OBJ += obj/sram.o \
OBJ += obj/sram.o \
obj/eeprom.o \
obj/svp.o \
obj/ssp16.o \
@ -94,7 +94,7 @@ obj/%.o : ../cart_hw/svp/%.c
obj/%.o : ../cart_hw/svp/%.c ../cart_hw/svp/%.h
$(CC) -c $< -o $@ $(FLAGS)
obj/%.o : ../cpu/%.c ../cpu/%.h
obj/%.o : ../z80/%.c ../z80/%.h
$(CC) -c $< -o $@ $(FLAGS)
obj/%.o : ../m68k/%.c ../m68k/%.h

View File

@ -75,13 +75,6 @@ int main (int argc, char *argv[])
return (0);
}
/* load SRAM */
FILE *f = fopen("./game.srm", "rb");
if (f!=NULL)
{
fread(&sram.sram,0x10000,1, f);
fclose(f);
}
/* load BIOS */
memset(bios_rom, 0, sizeof(bios_rom));
@ -117,6 +110,15 @@ int main (int argc, char *argv[])
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();
/* emulation loop */
@ -146,7 +148,7 @@ int main (int argc, char *argv[])
fclose(f);
}
trash_machine();
trash_machine();
system_shutdown();
error_shutdown();
return (0);
@ -184,11 +186,6 @@ 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)
{
@ -205,11 +202,6 @@ void dos_update_input(void)
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))
{
@ -270,30 +262,26 @@ void dos_update_input(void)
if(joy[1].button[7].b) input.pad[1] |= INPUT_MODE;
}
}
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;
/* 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(check_key(KEY_A)) error("ButtonA pressed\n");
if(key[KEY_A]) {
input.pad[joynum] |= INPUT_A;
}
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]) {
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;
input.pad[joynum] |= INPUT_START;
}
if(key[KEY_F]) input.pad[joynum] |= INPUT_START;
extern uint8 pico_current;
if (input.dev[joynum] == DEVICE_LIGHTGUN)
@ -302,17 +290,14 @@ void dos_update_input(void)
if(mouse_needs_poll() == TRUE)
poll_mouse();
/* 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;;
/* 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;
/* Map mouse buttons to player #1 inputs */
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)
{
@ -320,16 +305,20 @@ void dos_update_input(void)
if(mouse_needs_poll() == TRUE)
poll_mouse();
/* Get X & Y quantity of movement */
get_mouse_mickeys(&input.analog[2][0], &input.analog[2][1]);
/* Sega Mouse range is -256;+256 */
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];
/* Vertical movement is upsidedown */
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)
{
@ -337,11 +326,9 @@ void dos_update_input(void)
if(mouse_needs_poll() == TRUE)
poll_mouse();
/* Calculate X axis value */
input.analog[0][0] = 0x3c + (mouse_x * (0x17c - 0x3c + 1) / SCREEN_W);
/* Calculate Y axis value */
input.analog[0][1] = 0x1fc + (mouse_y* (0x3f3 - 0x1fc + 1) / SCREEN_H);
/* 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;
/* Map mouse buttons to player #1 inputs */
if(mouse_b & 2) input.pad[0] |= INPUT_B;
@ -387,7 +374,7 @@ void dos_update_input(void)
/* reinitialize timings */
system_init ();
audio_init(48000);
audio_init(option.sndrate);
fm_restore();
/* reinitialize HVC tables */
@ -399,10 +386,10 @@ void dos_update_input(void)
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_TAB)) set_softreset();
}
@ -516,7 +503,7 @@ void dos_update_video(void)
{
//blit(gen_bmp, screen, 0x0, 0, center_x, center_y, width, height);
stretch_blit(gen_bmp, screen, 0, 0, width, height, (SCREEN_W-352)/2, (SCREEN_H-240)/2, 352,240);
stretch_blit(gen_bmp, screen, 0, 0, width, height, (SCREEN_W-352)/2, (SCREEN_H-240)/2, 352,240 << (interlaced ? 1:0));
}
}

View File

@ -20,21 +20,6 @@ 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;

View File

@ -18,4 +18,5 @@
#include "fileio.h"
volatile int frame_count;
#endif /* _OSD_H_ */

View File

@ -1,3 +1,3 @@
To be compiled with DJGPP.
COmpile with DJGPP.
You will also need to install Allegro and Seal libraries.
Zlib is required for zipped rom support.

View File

@ -8,12 +8,12 @@
# LSB_FIRST : for little endian systems.
# X86_ASM : enable x86 assembly optimizations
NAME = gp_sdl
NAME = gp_sdl.exe
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
INCLUDES = -I. -I.. -I../z80 -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
@ -88,7 +88,7 @@ obj/%.o : ../cart_hw/svp/%.c
obj/%.o : ../cart_hw/svp/%.c ../cart_hw/svp/%.h
$(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@
obj/%.o : ../cpu/%.c ../cpu/%.h
obj/%.o : ../z80/%.c ../z80/%.h
$(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@
obj/%.o : ../m68k/%.c ../m68k/%.h
@ -98,8 +98,8 @@ obj/%.o : ./%.c ./%.h
$(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) $< -o $@
pack :
strip $(EXE)
upx -1 $(EXE)
strip $(NAME)
upx -9 $(NAME)
clean:
rm -f $(OBJECTS) $(NAME)

View File

@ -17,8 +17,8 @@ void set_config_defaults(void)
config.boost = 1;
config.filter = 0;
config.hq_fm = 1;
config.fm_core = 0;
config.hq_fm = 0;
config.fm_core = 1;
/* system options */
config.freeze_auto = -1;

View File

@ -1,3 +1,7 @@
/*
error.c --
Error logging
*/
#include "osd.h"

View File

@ -7,33 +7,43 @@ int timer_count = 0;
int old_timer_count = 0;
int paused = 0;
int frame_count = 0;
int frameticker = 0;
int joynum = 0;
int update_input(void);
unsigned char *keystate;
unsigned char buf[0x24000];
uint8 log_error = 1;
uint8 log_error = 0;
uint8 debug_on = 0;
uint8 turbo_mode = 0;
Uint32 fps_callback(Uint32 interval)
{
if(paused) return 1000/60;
if(paused) return 1000/vdp_rate;
timer_count++;
if(timer_count % 60 == 0)
frameticker ++;
if(timer_count % vdp_rate == 0)
{
int fps = frame_count;
char caption[32];
sprintf(caption, "Genesis Plus/SDL FPS=%d", fps);
int fps = frame_count + 1;
char caption[100];
char region[10];
if (region_code == REGION_USA) sprintf(region,"USA");
else if (region_code == REGION_EUROPE) sprintf(region,"EUR");
else sprintf(region,"JAP");
sprintf(caption, "Genesis Plus/SDL - %s (%s) - %d fps (%d)", rominfo.international, region, fps, turbo_mode);
SDL_WM_SetCaption(caption, NULL);
frame_count = 0;
}
return 1000/60;
return 1000/vdp_rate;
}
int main (int argc, char **argv)
{
int running = 1;
int sym;
SDL_Rect viewport, src;
SDL_Surface *bmp, *screen;
@ -61,17 +71,9 @@ int main (int argc, char **argv)
exit(1);
}
/* load SRAM */
FILE *f = fopen("./game.srm", "rb");
if (f!=NULL)
{
fread(&sram.sram,0x10000,1, f);
fclose(f);
}
/* load BIOS */
memset(bios_rom, 0, sizeof(bios_rom));
f = fopen("./BIOS.bin", "rb");
FILE *f = fopen("./BIOS.bin", "rb");
if (f!=NULL)
{
fread(&bios_rom, 0x800,1,f);
@ -88,20 +90,30 @@ int main (int argc, char **argv)
else config.bios_enabled = 0;
/* initialize SDL */
viewport.x = 0;
viewport.y = 0;
viewport.w = 640;
viewport.h = 480;
src.x = 0;
src.y = 0;
src.w = viewport.w;
src.h = viewport.h;
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);
viewport.x = 0;
viewport.y = 0;
bmp = SDL_CreateRGBSurface(SDL_SWSURFACE, 360, 576, 16, 0xF800, 0x07E0, 0x001F, 0x0000);
/* initialize Genesis screen */
memset(&bitmap, 0, sizeof(t_bitmap));
bitmap.width = 1024;
bitmap.height = 512;
bitmap.width = 360;
bitmap.height = 576;
bitmap.depth = 16;
bitmap.granularity = 2;
bitmap.pitch = (bitmap.width * bitmap.granularity);
@ -117,19 +129,32 @@ int main (int argc, char **argv)
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);
/* initialize emulation */
system_init();
audio_init(44100);
int buf_len = (48000 * 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);
audio_init(48000);
/* load SRAM */
f = fopen("./game.srm", "rb");
if (f!=NULL)
{
fread(&sram.sram,0x10000,1, f);
fclose(f);
}
/* reset emulation */
system_reset();
/* emulation loop */
SDL_SetTimer(1000/60, fps_callback);
SDL_SetTimer(1000/vdp_rate, fps_callback);
SDL_ShowCursor(0);
int now, prev = SDL_GetTicks();
while(running)
{
while (SDL_PollEvent(&event))
@ -147,6 +172,75 @@ int main (int argc, char **argv)
}
break;
case SDL_KEYDOWN: /* user options */
sym = event.key.keysym.sym;
if(sym == SDLK_TAB) system_reset();
if(sym == SDLK_F5) log_error ^=1;
if(sym == SDLK_F6)
{
turbo_mode ^=1;
frameticker = 0;
}
else if(sym == SDLK_F7)
{
f = fopen("game.gpz","r+b");
if (f)
{
fread(&buf, 0x23000, 1, f);
state_load(buf);
fclose(f);
}
}
else if(sym == SDLK_F8)
{
f = fopen("game.gpz","w+b");
if (f)
{
state_save(buf);
fwrite(&buf, 0x23000, 1, f);
fclose(f);
}
}
else if(sym == SDLK_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;
/* reinitialize overscan area */
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;
}
else if(sym == SDLK_F10) set_softreset();
else if(sym == SDLK_F11)
{
joynum ++;
if (joynum > MAX_DEVICES - 1) joynum = 0;
while (input.dev[joynum] == NO_DEVICE)
{
joynum ++;
if (joynum > MAX_DEVICES - 1) joynum = 0;
}
}
else if(sym == SDLK_ESCAPE) running = 0;
else if(sym == SDLK_F12)
{
config.overscan ^= 1;
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;
}
break;
default:
break;
}
@ -154,77 +248,131 @@ int main (int argc, char **argv)
if(!paused)
{
frame_count++;
if(!system_frame(0))
system_reset();
if(bitmap.viewport.changed)
if (frameticker > 1)
{
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);
/* Frame skipping */
frameticker--;
system_frame (1);
}
else
{
/* Delay */
while (!frameticker && !turbo_mode) SDL_Delay(1);
system_frame (0);
frame_count++;
}
frameticker--;
if(bitmap.viewport.changed)
{
bitmap.viewport.changed = 0;
src.w = (bitmap.viewport.w + 2 * bitmap.viewport.x);
src.h = (bitmap.viewport.w + 2*bitmap.viewport.x) << ((config.render && interlaced) ? 1:0);
viewport.w = bitmap.viewport.w + 2*bitmap.viewport.x;
viewport.h = bitmap.viewport.h + 2*bitmap.viewport.y;
viewport.x = (640 - viewport.w)/2;
viewport.y = ((480 - viewport.h)/2);
}
SDL_BlitSurface(bmp, &src, screen, &viewport);
//SDL_Flip(screen);
SDL_UpdateRect(screen, viewport.x, viewport.y, viewport.w, viewport.h);
}
}
}
system_shutdown();
SDL_Quit();
error_shutdown();
system_shutdown();
SDL_FreeSurface(bmp);
SDL_FreeSurface(screen);
SDL_Quit();
error_shutdown();
return 0;
}
/* Check if a key is pressed */
int check_key(int code)
{
static char lastbuf[0x100] = {0};
if((!keystate[code]) && (lastbuf[code] == 1))
lastbuf[code] = 0;
if((keystate[code]) && (lastbuf[code] == 0))
{
lastbuf[code] = 1;
return (1);
}
return (0);
return 0;
}
int update_input(void)
{
int running = 1;
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;
while (input.dev[joynum] == NO_DEVICE)
{
joynum ++;
if (joynum > MAX_DEVICES - 1) joynum = 0;
}
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;
/* reset input */
input.pad[joynum] = 0;
/* keyboard */
if(keystate[SDLK_UP]) input.pad[joynum] |= INPUT_UP;
else
if(keystate[SDLK_DOWN]) input.pad[joynum] |= INPUT_DOWN;
if(keystate[SDLK_LEFT]) input.pad[joynum] |= INPUT_LEFT;
else
if(keystate[SDLK_RIGHT]) input.pad[joynum] |= INPUT_RIGHT;
if(keystate[SDLK_TAB]) system_reset();
if(keystate[SDLK_a]) input.pad[joynum] |= INPUT_A;
if(keystate[SDLK_s]) input.pad[joynum] |= INPUT_B;
if(keystate[SDLK_d]) input.pad[joynum] |= INPUT_C;
if(keystate[SDLK_f]) input.pad[joynum] |= INPUT_START;
if(keystate[SDLK_z]) input.pad[joynum] |= INPUT_X;
if(keystate[SDLK_x]) input.pad[joynum] |= INPUT_Y;
if(keystate[SDLK_c]) input.pad[joynum] |= INPUT_Z;
if(keystate[SDLK_v]) input.pad[joynum] |= INPUT_MODE;
if(keystate[SDLK_ESCAPE]) running = 0;
return (running);
extern uint8 pico_current;
if (input.dev[joynum] == DEVICE_LIGHTGUN)
{
/* get mouse (absolute values) */
int x,y;
int state = SDL_GetMouseState(&x,&y);
/* Calculate X Y axis values */
input.analog[joynum - 4][0] = (x * bitmap.viewport.w) / 640;
input.analog[joynum - 4][1] = (y * bitmap.viewport.h) / 480;
/* Map mouse buttons to player #1 inputs */
if(state & SDL_BUTTON_MMASK) input.pad[joynum] |= INPUT_C;
if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_B;
if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_A;
}
else if (input.dev[joynum] == DEVICE_MOUSE)
{
/* get mouse (relative values) */
int x,y;
int state = SDL_GetRelativeMouseState(&x,&y);
/* Sega Mouse range is -256;+256 */
input.analog[2][0] = x;
input.analog[2][1] = y;
/* Vertical movement is upsidedown */
if (!config.invert_mouse) input.analog[2][1] = 0 - input.analog[2][1];
/* Map mouse buttons to player #1 inputs */
if(state & SDL_BUTTON_MMASK) input.pad[joynum] |= INPUT_C;
if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_A;
if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_B;
}
else if (system_hw == SYSTEM_PICO)
{
/* get mouse (absolute values) */
int x,y;
int state = SDL_GetMouseState(&x,&y);
/* Calculate X Y axis values */
input.analog[0][0] = 0x3c + (x * (0x17c-0x03c+1)) / 640;
input.analog[0][1] = 0x1fc + (y * (0x2f7-0x1fc+1)) / 480;
/* Map mouse buttons to player #1 inputs */
if(state & SDL_BUTTON_MMASK) pico_current++;
if(state & SDL_BUTTON_RMASK) input.pad[joynum] |= INPUT_A;
if(state & SDL_BUTTON_LMASK) input.pad[joynum] |= INPUT_B;
}
/* options */
return (1);
}

View File

@ -7,6 +7,7 @@
extern uint8 debug_on;
extern uint8 log_error;
extern int frame_count;
#endif /* _MAIN_H_ */

View File

@ -1,3 +1,5 @@
To be compiled with MinGW.
You will also need to install SDL library
Zlib is required for zipped rom support.
Compile with MinGW.
You will also need to install the SDL library (http://www.libsdl.org/).
Zlib is required for zipped rom support.
Please distribute required dlls with the executable.

View File

@ -626,7 +626,9 @@ void vdp_data_w(unsigned int data)
return;
}
/* FIFO emulation */
/* update VDP FIFO (during HDISPLAY only) */
if (!(status&8) && (reg[1]&0x40))
{
fifo_update();
if (fifo_write_cnt == 0)
{
@ -647,6 +649,7 @@ void vdp_data_w(unsigned int data)
/* VDP latency (Chaos Engine, Soldiers of Fortune, Double Clutch) */
if (fifo_write_cnt > 4) count_m68k = fifo_lastwrite + fifo_latency;
}
}
/* write data */