updated documentation, added preliminar sound support for SDL/WIN32 port

This commit is contained in:
ekeeke31 2008-08-25 15:27:53 +00:00
parent 201c5eb922
commit 63ca498fc9
12 changed files with 285 additions and 156 deletions

View File

@ -13,7 +13,6 @@
** History:
**
** 2006-2008 Eke-Eke (Gamecube/Wii genesis plus port):
** - added DAC filtering
** - fixed internal FM timer emulation
** - removed unused multichip support and YMxxx support
** - fixed CH3 CSM mode (credits to Nemesis)
@ -920,7 +919,7 @@ INLINE void advance_eg_channel(FM_SLOT *SLOT)
i = 4; /* four operators per channel */
do
{
/* reset swap_flag (EkeEke) */
/* reset SSG-EG swap flag (Eke-Eke) */
swap_flag = 0;
switch(SLOT->state)

View File

@ -1,3 +1,168 @@
Genesis Plus History
--------------------
Note: All recent changes directly come from the Gamecube/Wii port, coded by Eke-Eke.
[current]
- (MAME YM2612) fixed LFO phase update for CH3 special mode: fix sound effects in Warlock & Aladdin (thanks to AamirM)
- (MAME YM2612) fixed enveloppe attenuation level on "KEY ON": fix Ecco 2's splash sound
- (MAME YM2612) minor fixes on SSG-EG emulation
- (MAME YM2612) added libsamplerate (Secret Rabbit Code) support for better FM resampling (HQ mode)
- (VDP) implemented cycle-accurate HINT timings: every timing sensitive games/demos are now *finally* working fine
- (VDP) fixed a bug affecting CRAM/VSRAM DMA timings
- (VDP) fixed Sprite Attribute Table address mask for VRAM writes
- (CPU) improved accuracy of 68k access to Z80: fix music in Pacman 2 when entering PAUSE menu
- (CPU) disabled "Address Error" emulation when UMK3 hack is loaded: fix game crashing after a round ends up
- (CART) added support for some more unlicensed games: Pocket Monster, King of Fighter 98, Soul Blade (credits to Haze)
- (IO) improved Menacer emulation: fix lightgun support in Body Count & T2: The Arcade Game
- (IO) implemented Konami Justifier emulation: fix lightgun support in Lethal Enforcers 1 & 2
- (IO) implemented Sega Mouse emulation (Populous 2, Body Count, Shangai 2, Fun'n Games, ...)
[07/16/08] (Eke-Eke)
- adjusted (again) HINT timings: fix Double Dragon 2 (game freezed), hopefully does not break anything else
- fixed broken EEPROM support for Codemaster games
- modified input update timings: fix Dungeons & Dragons - Warriors of the Eternal Sun (thanks to Notaz)
- added support for "Ultimate Mortal Kombat Trilogy" hack (max. size supported is 10MBytes)
- added (VERY) preliminar support for PICO roms (credits to Notaz for his documentation)
- improved YM2612 emulation (credits to Nemesis for his tests on real hardware):
.implemented phase overflow emulation: improved fix for special music instrument used in Comix Zone, Flashback, Ariel, Shaq Fu...
.improved SSG-EG emulation in MAME core (also based on additional code from Alone Coder)
.improved Timers emulation accuracy
.improved Enveloppe Generator accuracy
.fixed Channel 3 CSM mode emulation
.implemented sample interpolation in MAME core to emulate the chip at original frequency (HQ YM2612 mode, from gens)
[06/01/08] (Eke-Eke)
- improved HCounter accuracy: fix graphic glitches in "Striker (Europe)"
- improved HINT timing accuracy: fix flickering in "Zero The Kamikaze Squirrel (USA)"
- improved rendering accuracy when backdrop color is modified during HBLANK (Road Rash I/II/III)
- fixed broken Game Genie support
[04/19/08] (Eke-Eke)
- modified VINT timings a little bit: fix lockup during Desert Strike's intro
- corrected 68k interrupts handling: fix graphic glitches in Darius II/Sagaia
[04/06/08] (Eke-Eke)
- updated SVP core: fix some perspective issues in Virtua Racing (thanks to Notaz)
- added internal SAT update during VRAM Fill: fix unmasked sprites during Battletech's intro
- fixed m68k core issues with gcc 4.2.3: fix Xperts, Lemmings 2, M1 Abrams Battle Tank
- forced YM2612 Enveloppe update: fix intro music in Batman&Robin (thanks to Aamir)
[03/01/08] (Eke-Eke)
- added SVP emulation: Virtua Racing is now emulated (big thanks to Notaz and TascoDeluxe)
- fixed VDP registers behaviour when VDP Mode 4 is enabled: fix Bass Masters Classic Pro, Captain Planet & The Planeeters
- corrected a bug in DMA Fill operation: fix James Pond 3, Rockman World/Megaman Willy Wars (corrupted VRAM)
- corrected typo errors in CPU cycle counters update: fix optiom screen music in "College Slam" and probably others games.
- added preliminary support of undocumented YM2612 bug: fixes soundtracks of Shaq Fu, Spiderman, Comix Zone, Ariel and some others
- added support for mappers & copy protection devices used in many unlicensed/pirate cartridges (see cart_hw.c for details)
- rewrote memory handlers for better modularity and some (little) speedup
- reduced Savestate size
[01/07/08] (Eke-Eke)
- fixed interleaved rom detection: roms with .smd extension should now work fine
- fixed a recently introduced bug in VDP registers writes: fixes bad colors in Toy Story (intro)
- updated list of games using EEPROM: added Sports Talk Baseball (internal memory check fixed) and Brian Lara Cricket
- fixed VINT flag update when VINT is disabled: fixes NCAA College Football
- adjusted DMA timings in H32 mode: fixes flickering in Out of this World, Kawasaki Superbike Challenge & Formula One
- adjusted line rendering and HBLANK timings: fixes flickering in Nigel Mansell's World Championship Racing, Deadly Moves/Power Athlete
- fixed unmapped ROM reads through Z80 Bank: fixes Zombie High (Proto)
- added support for custom ROM/RAM mapping used by Game no Kanzume Otokuyou
[12/28/07] (Eke-Eke)
- many sourcecode cleanup and optimization
- completely rewrote EEPROM emulation: now support all known EEPROM types (24C01-24C65) and mappers (Sega, Acclaim, EA, Codemasters)
used in a few games (now use internal game database) as external RAM. This should at least fix save support in the following games:
. NBA Jam (alternate Acclaim mapper)
. College Slam, Frank Thomas Big Hurt Baseball (24C65 type)
. NHLPA Hockey 93, Rings of Power (EA mapper)
. Micro Machines serie, Brian Lara Cricket 96/Shane Warne Cricket (Codemasters mapper)
- external RAM is now initialized to 0xFF by default: fix Micromachines 2, Dino Dini Soccer
- fixed SRAM 16-bits memory handlers: fix some Sega Sports and EA Sports games (NFL95, NBA Action 95, NHL97, NHL98,...)
- modified WRITE_xxx & READ_xxx macros for better portability and faster memory access on BIG ENDIAN platform
- completely rewrote BIG ENDIAN support in render.c and vdp.c: rendering should be a little faster
- rewrote ROM bankswitch emulation (Super Street Fighter II): ROM access are faster, using memory pointers instead of reading ROM copy from ARAM
- fixed leftmost Window/PlaneA column render and implemented Window bug (as described by Charles Mc Donald)
- improved "Sprite Limit" and "Sprite Collision" detection accuracy
- modified RGB565 Color Palette to use the full available color range (0-31;0-63)
- implemented "cycle accurate" HV Interrupt timings: fix Sesame's Street Counting Cafe, Legend of Galahad (intro)
- improved VDP access timings accuracy (added FIFO emulation): fix Double Clutch
- improved DMA timings accuracy: fix Winter Olympics (E), Arch Rivals and probably more
- fixed HCounter again: Road Rash serie (I,II,III) don't need timing hacks anymore
- fixed VCounter in Interlaced 2 mode: fix Combat Cars "VS-Mode"
- improved Interlaced 2 mode (double resolution) rendering: Sonic 2, Combat Cars ("VS-Modes") look far better
- added TMSS BIOS support (optional)
- rewrote part of the YM2162 MAME's core: fixed internal FM timers handling, removed non-YM2612 emulation code and unused multiple cpu support
- implemented "cycle accurate" FM timers & sound samples rendering
- improved Z80 Interrupt timing accuracy: fix Sonic 3 music slowdowns
- updated Z80 & 68000 cores to last MAME versions
- improved Soft Reset emulation: X-Men 2 and Eternal Champions (random character selection) now work more like on real hardware.
- added full overscan emulation (vertical & horizontal borders) for "pixel perfect" aspect ratio (tested against a real genesis)
[07/20/07] (Eke-Eke)
- corrected TeamPlayer support: fix multiplayer in Gauntlet 4 (Sept. version), Pengo and a lot of others
- added J-Cart support: enable multiplayer in Codemasters games (Pete Sampras, Micromachines games, Super Skidmarks)
- added serial EEPROM autodetection: fix games with bad SRAM informations in header (NBA Jam TE)
- added SVP faking: display 2D graphics in Virtua Racing (the game is however still unplayable)
- added support for more internal IO registers: fixe some unlicensed games (Wisdom Tree games...)
- added preliminary support for unmapped protection device: fix some unlicensed games with special built-in hardware (Squirell King, Lion King 2...)
- added "Soft Reset" combo (in game, use L+Z triggers): this should be like pressing the RESET button on a real Genesis and this is required
in some games to enable special features or even complete the game (ex: X-Men).
[06/21/07] (Eke-Eke)
- added Multitap support (EA 4-Way Play and Sega Teamplayer): allowed up to four players in games supporting those peripherals
- added partial Sega Menacer lightgun support (use Analog Stick): automatically set when detecting the 6-in-1 Menacer game
[05/18/07] (Eke-Eke)
- you can now switch between FM cores without reseting the game. FM registers value are automatically restored when switching.
- removed the previous VINT timings modification because it brokes some games (Rocket Knight, Thunderforce III,...)
- added automatic Timing configuration (VDP latency, VINT timing & alternate Line Timing) at game loading, based upon specific romname detection.
This means you can still modify some of these options afterwards but they are now automatically set/unset when loading a game which need
special timing fixes. These fixes are also automatically desactivated when the current game doesn't need them.
For information, games that are actually detected and need special timings to run properly are:
.Legend of Galahad & Road Rash series (single line not rendered properly)
.Sesame Street Counting Cafe (don't boot)
.Chaos Engine/Soldiers of Fortune (graphic glitches on scrolling)
[05/08/07] (Eke-Eke)
- VINT timings are now a little more accurate: fixes Sesame's Street Counting Cafe
- SN76496 MAX_OUTPUT back to normal
- modified FB_WNOISE value in SN76496 core according to John Kortink's last informations
- added support for Maxim's PSG core, same as used in SMSPLUS (it becomes the default PSG core)
- updated FM core to the latest MAME version
- corrected DAC output level (fixes voices and some special FX being too low)
- added support for Gens YM2612 (FM) core (MAME's one still remains default FM core)
- added configurable preamplification for each sound cores (see Emulator Options)
- added some other configurable sound options (boost overall volume, FM improvment for Gens YM2612)
[04/11/07] (Eke-Eke)
- corrected MAX_OUTPUT value in SN76496 core: fix PSG sound (SFX) volume
[03/17/07] (Eke-Eke)
- added an option to enable alternate line rendering timing (fix single line error in Road Rash series and Legend of Galahad's Intro)
- Color RAM update now always reset color 0 to border color (fix color glitches in Mortal Kombat,...) (thanks to Noop's for the idea)
[03/09/07] (Eke-Eke)
- modified HV counter tables (fix graphic glitches in Skitchin's sky, Lotus 2 Recs, Panorama Cotton, Dashin Desperados & maybe more)
- completely rewrote DMA timings emulation so that it works for all games (no more cpu freezing)
- added all DMA tranfer rates handling for each three DMA modes and added dma busy flag emulation
- modified interrupts handling on VDP register #0 and #1 writes (fix Lemmings status bar)
- added VDP RAM write latency (fix Chaos Engine/Soldier of Fortune gfx glitches)
- modified FM timers handling a bit (fix Vectorman2 music)
- corrected Sprite Limit rendering (fix Sonic 1 & Micromachines 2 title screens)
- corrected IO Registers writes (fix Decap' Attack controls, no more need for alternate input)
- corrected 6 Buttons Pad emulation (fix 6buttons detection in Mortal Kombat 3, Comix Zone and other 6-buttons compatible games)
- modified sound mixing a bit according to Generator sourcecode (FM and PSG ratios seems more correct)
[02/07/07] (Eke-Eke)
- fixed fm timers (fix missing music in Castle of Illusion, Quackshot, Undead Line, Wonderboy in Monster Lair, Cal 50, Turbo Outrun, Thundeforce 4 and maybe more)
- added complete EEPROM emulation (save support now works fine in Wonderboy5, Megaman Willy Wars, NBA Jam...) (credits to Notaz, adapted from Picodrive code)
- added preliminar dma timing emulation (fix bottom screen in Legend of Galahad) (credits to Notaz, adapted from Picodrive code)
- hack: clear Vint pending after Hint (INT level 4) acknowledge (fix Fatal Rewind)
- hack: modify read_bus16 to return a random value (fake fetch) (fix Time Killers)
- modified cpu execution timings, with more correct hblank and interrupts timing (fix ISS Deluxe, Double Dragon 2 and certainly more) (Based on Gens code)
- modified busreq mechanism: better synchro between z80 & 68k (no need to dejitter anymore) (Based on Gens code)
- added sprite collision detection (fix Strider 2)
- modified dma fill operation for big endian platform (fix Contra Hardcorps gfx garbage)
[05/25/03]
- Fixed a typo that made Z80 banked access to the VDP registers always fail.

View File

@ -6,14 +6,38 @@
by Charles Mac Donald
WWW: http://cgfm2.emuviews.com
additional code by Eke-Eke
WWW: http://gxdev.wordpress.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
see CHANGELOG
Features (NEW!)
---------
* cycle-accurate CPUs emulation & synchronization (68000, Z80, YM2612, SN76489)
* cycle-accurate VDP emulation (DMA, FIFO, HV interrupts, HBLANK,…)
* original frequency YM2612 emulation (High Quality FM)
* basic hardware latency emulation
* full overscan area (horizontal & vertical colored borders) emulation
* TMSS BIOS support
* PICO hardware support (experimental)
* 3-buttons & 6-buttons controllers
* Sega Team Player & EA 4-Way Play multitap adapters (up to 8players !)
* Sega Menacer & Konami Justifier lightguns
* Sega Mouse & Sega Mega Mouse
* SVP DSP (Virtua Racing)
* J-Cart
* backup RAM (parallel SRAM/FRAM and serial EEPROM)
* ROM bankswitch (Super Street Fighter 2)
* SRAM switch (Phantasy Star 4, Legend of Thor, Sonic the Hedgehog 3)
* ROM mappers & copy protection devices used in many unlicensed/pirate cartridges
Usage
-----
@ -28,17 +52,33 @@
Arrow Keys - Directional pad
A,S,D,F - 1P gamepad, buttons A, B, C, Start
Tab - Reset
Tab - Hard Reset
Esc - Exit program
F7 - Load Savestate (game.gpz)
F8 - Save Savestate (game.gpz)
F9 - Toggle CPU clock: PAL(50hz)/NTSC(60hz)
F10 - Soft Reset
F11 - Toggle Player # (keyboard/mouse)
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
F5 - Log 68k memory access (for debug ONLY)
F6 - Log messages (for debug ONLY)
WIndows only:
End - Exit program
F1-F4 - Set frameskip level (F1 = no skip ... F4 = skip 3 frames)
F5 - Log messages (for debug ONLY)
F6 - Toggle Turbo mode
The mouse can be used for lightgun games, PICO games and when the Sega Mouse is activated.
A SRAM file (game.srm) is automatically saved on exit and loaded on startup.
DOS details:
@ -90,15 +130,30 @@
suggestions that have made Genesis Plus a better program.
(http://www.bannister.org)
Extra features, emulation accuracy & game compatibility improvments by Eke-Eke
(from the Gamecube/Wii port: http://code.google.com/p/genplus-gx )
The Genesis emulator authors: Bart Trzynadlowski, Quintesson, Steve Snake,
James Ponder, Stef, Gerrie, Sardu.
James Ponder, Stef, Gerrie, Sardu, Haze, Notaz, Nemesis, AamirM
The regular people and many lurkers at segadev.
People from SpritesMind.net forums
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.
Maxim for his SN76489 emulator
Stef (again) for his alternate YM2612 emulator
Notaz for his SVP emulator
Tasco Deluxe for his documentation of Realtec mapper
Erik de Castro Lopo for his "Secret Rabbit Code" library aka libsamplerate
Jean-Loup Gailly and Mark Adler for their useful zip library
Contact
-------
@ -107,6 +162,10 @@
E-mail: cgfm2@hotmail.com
WWW: http://cgfm2.emuviews.com
Eke-Eke
E-mail: eke_eke31@yahoo.fr
WWW: http://gxdev.wordpress.com/
Legal
-----
@ -115,8 +174,7 @@
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
The Z80 CPU emulator, 68K CPU emulator, and the YM2612 emulation code
are taken from the MAME project, and terms of their use are covered under
the MAME license.
(http://www.mame.net)
the MAME license. (http://www.mame.net)

View File

@ -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

View File

@ -62,7 +62,7 @@ OBJ += obj/dos.o \
obj/fileio.o \
obj/loadrom.o
EXE = gen.exe
EXE = ../gen.exe
all : $(EXE)

View File

@ -94,9 +94,6 @@ void set_option_defaults(void)
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;

View File

@ -54,22 +54,15 @@ typedef struct
****************************************************************************/
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;

View File

@ -97,6 +97,7 @@ int main (int argc, char *argv[])
init_machine();
/* default config */
do_config("genplus.cfg");
set_config_defaults();
input.system[0] = SYSTEM_GAMEPAD;
input.system[1] = SYSTEM_GAMEPAD;
@ -379,8 +380,8 @@ void dos_update_input(void)
bitmap.viewport.changed = 1;
}
if(check_key(KEY_F10)) system_reset();
if(check_key(KEY_TAB)) set_softreset();
if(check_key(KEY_F10)) set_softreset();
if(check_key(KEY_TAB)) system_reset();
}
void dos_update_audio(void)

View File

@ -8,7 +8,7 @@
# LSB_FIRST : for little endian systems.
# X86_ASM : enable x86 assembly optimizations
NAME = gp_sdl.exe
NAME = ../gen_sdl.exe
CC = gcc
CFLAGS = `sdl-config --cflags` -O6 -march=i686 -fomit-frame-pointer

View File

@ -1,16 +1,11 @@
#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;
@ -21,17 +16,11 @@ void set_config_defaults(void)
config.fm_core = 1;
/* 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;

View File

@ -8,22 +8,15 @@
****************************************************************************/
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;

View File

@ -16,16 +16,16 @@ int update_input(void);
unsigned char *keystate;
unsigned char buf[0x24000];
SDL_AudioSpec audio;
static uint8 soundbuffer[2][3840];
static uint8 mixbuffer[16000];
static int mixhead = 0;
static int mixtail = 0;
static int whichab = 0;
uint8 log_error = 1;
uint8 log_error = 0;
uint8 debug_on = 0;
uint8 turbo_mode = 0;
uint8 use_sound = 1; /* NOT WORKING */
static int mixercollect( uint8 *outbuffer, int len )
{
@ -33,7 +33,6 @@ static int mixercollect( uint8 *outbuffer, int len )
uint32 *src = (uint32 *)mixbuffer;
int done = 0;
/*** Always clear output buffer ***/
memset(outbuffer, 0, len);
while ( ( mixtail != mixhead ) && ( done < len ) )
@ -59,7 +58,7 @@ Uint32 fps_callback(Uint32 interval)
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);
sprintf(caption, "Genesis Plus/SDL - %s (%s) - %d fps", rominfo.international, region, fps);
SDL_WM_SetCaption(caption, NULL);
frame_count = 0;
@ -84,12 +83,13 @@ int sdl_sound_init()
as.freq = SOUND_FREQUENCY;
as.format = AUDIO_S16;
as.channels = 2;
as.samples = SOUND_FREQUENCY/vdp_rate;
as.samples = snd.buffer_size;
as.callback = sdl_sound_callback;
if(SDL_OpenAudio(&as, 0) == -1) {
if(SDL_OpenAudio(&as, 0) == -1)
{
char caption[256];
sprintf(caption, "can't open audio");
sprintf(caption, "SDL open audio failed");
MessageBox(NULL, caption, "Error", 0);
return 0;
}
@ -99,7 +99,6 @@ int sdl_sound_init()
static void sdl_sound_update()
{
int i;
// SDL_LockAudio();
uint32 *dst = (uint32 *)mixbuffer;
for(i = 0; i < snd.buffer_size; ++i)
@ -107,7 +106,6 @@ static void sdl_sound_update()
dst[mixhead++] = (snd.buffer[0][i] << 16) | snd.buffer[1][i];
if (mixhead == 4000) mixhead = 0;
}
// SDL_UnlockAudio();
}
int main (int argc, char **argv)
@ -115,7 +113,7 @@ int main (int argc, char **argv)
int running = 1;
int sym;
SDL_Rect viewport, src;
SDL_Rect viewport, display;
SDL_Surface *bmp, *screen;
SDL_Event event;
@ -125,7 +123,7 @@ int main (int argc, char **argv)
if(argc < 2)
{
char caption[256];
sprintf(caption, "Genesis Plus\nby Charles MacDonald\nWWW: http://cgfm2.emuviews.com\nusage: %s gamename\n", argv[0]);
sprintf(caption, "Genesis Plus\SDL by Charles MacDonald\nWWW: http://cgfm2.emuviews.com\nusage: %s gamename\n", argv[0]);
MessageBox(NULL, caption, "Information", 0);
exit(1);
}
@ -172,10 +170,18 @@ int main (int argc, char **argv)
SDL_ShowCursor(0);
/* initialize SDL video */
viewport.x = 0;
viewport.y = 0;
viewport.w = 640;
viewport.h = 480;
screen = SDL_SetVideoMode(viewport.w, viewport.h, 16, SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE/* | SDL_FULLSCREEN*/);
display.x = 0;
display.y = 0;
display.w = 256;
display.h = 224;
bmp = SDL_CreateRGBSurface(SDL_SWSURFACE, 360, 576, 16, 0xF800, 0x07E0, 0x001F, 0x0000);
screen = SDL_SetVideoMode(viewport.w, viewport.h, 16, SDL_SWSURFACE);
if (!bmp || !screen)
{
char caption[256];
@ -205,10 +211,10 @@ int main (int argc, char **argv)
/* initialize emulation */
system_init();
audio_init(SOUND_FREQUENCY);
audio_init(48000);
/* initialize SDL audio */
//sdl_sound_init();
if (use_sound) sdl_sound_init();
/* load SRAM */
f = fopen("./game.srm", "rb");
@ -223,7 +229,7 @@ int main (int argc, char **argv)
/* start emulation loop */
SDL_SetTimer(1000/vdp_rate, fps_callback);
//SDL_PauseAudio(1);
if (use_sound) SDL_PauseAudio(1);
while(running)
{
@ -239,7 +245,7 @@ int main (int argc, char **argv)
if(event.active.state & (SDL_APPINPUTFOCUS | SDL_APPACTIVE))
{
paused = !event.active.gain;
//SDL_PauseAudio(paused);
if (use_sound) SDL_PauseAudio(paused);
}
break;
@ -279,7 +285,7 @@ int main (int argc, char **argv)
/* reinitialize timings */
system_init ();
audio_init(audio.freq);
audio_init(48000);
fm_restore();
/* reinitialize HVC tables */
@ -328,7 +334,7 @@ int main (int argc, char **argv)
else
{
/* Delay */
while (!frameticker && !turbo_mode) SDL_Delay(0);
while (!frameticker && !turbo_mode) SDL_Delay(1);
system_frame (0);
frame_count++;
@ -339,21 +345,28 @@ int main (int argc, char **argv)
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) << ((config.render && interlaced) ? 1:0);
viewport.w = bitmap.viewport.w + 2*bitmap.viewport.x;
viewport.h = bitmap.viewport.h + 2*bitmap.viewport.y;
display.w = (bitmap.viewport.w + 2*bitmap.viewport.x);
display.h = (bitmap.viewport.h + 2 * bitmap.viewport.y) << ((config.render && interlaced) ? 1:0);
viewport.w = bitmap.viewport.w;
viewport.h = bitmap.viewport.h;
viewport.x = (640 - viewport.w)/2;
viewport.y = ((480 - viewport.h)/2);
viewport.y = (480 - viewport.h)/2;
}
sdl_sound_update();
SDL_BlitSurface(bmp, &src, screen, &viewport);
//SDL_Flip(screen);
if (use_sound) sdl_sound_update();
SDL_BlitSurface(bmp, &display, screen, &viewport);
SDL_UpdateRect(screen, viewport.x, viewport.y, viewport.w, viewport.h);
}
}
/* save SRAM */
f = fopen("./game.srm", "wb");
if (f!=NULL)
{
fwrite(&sram.sram,0x10000,1, f);
fclose(f);
}
system_shutdown();
SDL_PauseAudio(1);
SDL_CloseAudio();