2011-07-14 00:49:52 +02:00
|
|
|
/***************************************************************************************
|
|
|
|
* Genesis Plus
|
----------------------
Genesis Plus GX 1.6.0
----------------------
[Core/Sound]
---------------
* added YM2413 emulation in Master System compatibility mode.
* fixed SN76489 noise boost initialization.
* minor YM2612 core optimizations.
[Core/VDP]
---------------
* added accurate emulation of SG-1000, Master System (315-5124, 315-5246) & Game Gear VDP.
* added support for all TMS9918 rendering modes.
* improved Mega Drive VDP timings accuracy in Master System Compatibility mode.
* fixed color palette initialization.
* fixed shifted sprites rendering in Mode 4.
* modified pixel rendering support (pixel depth is now forced at compilation time).
[Core/CPU]
---------------
* optimized 68k core (rewrote 68k interrupt handling, removed multiple CPU types support & unused code) for 5~8% speed improvment
[Core/IO]
---------------
* added accurate emulation of Master System (315-5216, 315-5237, 315-5297) & Game Gear I/O controllers.
* added Terebi Oekaki tablet emulation.
* improved Mouse emulation (fixes mouse support in Cannon Fodder).
* improved Justifier emulation (fixes gun support in Lethal Enforcers 2).
* improved 6-Buttons control pad emulation (fixes Duke Nukem 3D)
* modified lightgun emulation to use common key inputs for all devices.
* 2-buttons controller is now picked by default for Master System games.
[Core/MD]
---------------
* added copy-protection hardware emulation for some new dumped games (Tiny Toon Adventures 3, Mighty Morphin Power Rangers & The Battle of Red Cliffs).
* added Game Toshokan in EEPROM database (verified on real cartridge).
* fixed Micro Machines 2 - Turbo Tournament EEPROM size (verified on real cartridge).
* modified SRAM banswitch hardware emulation to be more compatible with some hacks.
[Core/MS]
---------------
* added Cyborg Z to Korean mapper database.
[Core/GG]
---------------
* added 93C46 EEPROM emulation (Majors Pro Baseball, World Series Baseball & World Series Baseball 95).
[Core/General]
---------------
* added support for .mdx ROM format.
* added Game Gear & SG-1000 ROM support.
* added accurate emulation of SG-1000, Master System (I, II) & Game Gear hardware models for 100% compatibility.
* updated to new Genesis Plus license (see http://cgfm2.emuviews.com/)
* removed DOS port
* various code cleanup.
[Gamecube/Wii]
---------------
* IMPORTANT: cheats, screenshots & save files are now stored in console-specific directories (ex: /snaps/md, /cheats/ms, /saves/gg, ...)
* added 8-bit Action Replay & Game Genie codes support (for Master System & Game Gear games).
* improved audio/video synchronization for PAL games in 50Hz TV modes (now use VSYNC like NTSC games in 60hz modes).
* improved gun cursor positioning accuracy.
* improved horizontal scaling & screenshots rendering in H32 mode.
* fixed a bug with ROM file extension handling that would affect cheats, snapshots, sram & savestate files.
* removed ARAM/injected ROM support (unused).
* removed WPAD_ and PAD_ update from VSYNC callback.
* increased GCC inlining limits for some speed improvment.
* compiled with devkitPPC r24 & libogc 1.8.7.
2011-08-07 19:49:46 +02:00
|
|
|
* Sound Hardware
|
2011-07-14 00:49:52 +02:00
|
|
|
*
|
2016-12-18 23:09:16 +01:00
|
|
|
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
|
2017-12-22 20:37:58 +01:00
|
|
|
* Copyright (C) 2007-2017 Eke-Eke (Genesis Plus GX)
|
2011-07-14 00:49:52 +02:00
|
|
|
*
|
----------------------
Genesis Plus GX 1.6.0
----------------------
[Core/Sound]
---------------
* added YM2413 emulation in Master System compatibility mode.
* fixed SN76489 noise boost initialization.
* minor YM2612 core optimizations.
[Core/VDP]
---------------
* added accurate emulation of SG-1000, Master System (315-5124, 315-5246) & Game Gear VDP.
* added support for all TMS9918 rendering modes.
* improved Mega Drive VDP timings accuracy in Master System Compatibility mode.
* fixed color palette initialization.
* fixed shifted sprites rendering in Mode 4.
* modified pixel rendering support (pixel depth is now forced at compilation time).
[Core/CPU]
---------------
* optimized 68k core (rewrote 68k interrupt handling, removed multiple CPU types support & unused code) for 5~8% speed improvment
[Core/IO]
---------------
* added accurate emulation of Master System (315-5216, 315-5237, 315-5297) & Game Gear I/O controllers.
* added Terebi Oekaki tablet emulation.
* improved Mouse emulation (fixes mouse support in Cannon Fodder).
* improved Justifier emulation (fixes gun support in Lethal Enforcers 2).
* improved 6-Buttons control pad emulation (fixes Duke Nukem 3D)
* modified lightgun emulation to use common key inputs for all devices.
* 2-buttons controller is now picked by default for Master System games.
[Core/MD]
---------------
* added copy-protection hardware emulation for some new dumped games (Tiny Toon Adventures 3, Mighty Morphin Power Rangers & The Battle of Red Cliffs).
* added Game Toshokan in EEPROM database (verified on real cartridge).
* fixed Micro Machines 2 - Turbo Tournament EEPROM size (verified on real cartridge).
* modified SRAM banswitch hardware emulation to be more compatible with some hacks.
[Core/MS]
---------------
* added Cyborg Z to Korean mapper database.
[Core/GG]
---------------
* added 93C46 EEPROM emulation (Majors Pro Baseball, World Series Baseball & World Series Baseball 95).
[Core/General]
---------------
* added support for .mdx ROM format.
* added Game Gear & SG-1000 ROM support.
* added accurate emulation of SG-1000, Master System (I, II) & Game Gear hardware models for 100% compatibility.
* updated to new Genesis Plus license (see http://cgfm2.emuviews.com/)
* removed DOS port
* various code cleanup.
[Gamecube/Wii]
---------------
* IMPORTANT: cheats, screenshots & save files are now stored in console-specific directories (ex: /snaps/md, /cheats/ms, /saves/gg, ...)
* added 8-bit Action Replay & Game Genie codes support (for Master System & Game Gear games).
* improved audio/video synchronization for PAL games in 50Hz TV modes (now use VSYNC like NTSC games in 60hz modes).
* improved gun cursor positioning accuracy.
* improved horizontal scaling & screenshots rendering in H32 mode.
* fixed a bug with ROM file extension handling that would affect cheats, snapshots, sram & savestate files.
* removed ARAM/injected ROM support (unused).
* removed WPAD_ and PAD_ update from VSYNC callback.
* increased GCC inlining limits for some speed improvment.
* compiled with devkitPPC r24 & libogc 1.8.7.
2011-08-07 19:49:46 +02:00
|
|
|
* Redistribution and use of this code or any derivative works are permitted
|
|
|
|
* provided that the following conditions are met:
|
2011-07-14 00:49:52 +02:00
|
|
|
*
|
----------------------
Genesis Plus GX 1.6.0
----------------------
[Core/Sound]
---------------
* added YM2413 emulation in Master System compatibility mode.
* fixed SN76489 noise boost initialization.
* minor YM2612 core optimizations.
[Core/VDP]
---------------
* added accurate emulation of SG-1000, Master System (315-5124, 315-5246) & Game Gear VDP.
* added support for all TMS9918 rendering modes.
* improved Mega Drive VDP timings accuracy in Master System Compatibility mode.
* fixed color palette initialization.
* fixed shifted sprites rendering in Mode 4.
* modified pixel rendering support (pixel depth is now forced at compilation time).
[Core/CPU]
---------------
* optimized 68k core (rewrote 68k interrupt handling, removed multiple CPU types support & unused code) for 5~8% speed improvment
[Core/IO]
---------------
* added accurate emulation of Master System (315-5216, 315-5237, 315-5297) & Game Gear I/O controllers.
* added Terebi Oekaki tablet emulation.
* improved Mouse emulation (fixes mouse support in Cannon Fodder).
* improved Justifier emulation (fixes gun support in Lethal Enforcers 2).
* improved 6-Buttons control pad emulation (fixes Duke Nukem 3D)
* modified lightgun emulation to use common key inputs for all devices.
* 2-buttons controller is now picked by default for Master System games.
[Core/MD]
---------------
* added copy-protection hardware emulation for some new dumped games (Tiny Toon Adventures 3, Mighty Morphin Power Rangers & The Battle of Red Cliffs).
* added Game Toshokan in EEPROM database (verified on real cartridge).
* fixed Micro Machines 2 - Turbo Tournament EEPROM size (verified on real cartridge).
* modified SRAM banswitch hardware emulation to be more compatible with some hacks.
[Core/MS]
---------------
* added Cyborg Z to Korean mapper database.
[Core/GG]
---------------
* added 93C46 EEPROM emulation (Majors Pro Baseball, World Series Baseball & World Series Baseball 95).
[Core/General]
---------------
* added support for .mdx ROM format.
* added Game Gear & SG-1000 ROM support.
* added accurate emulation of SG-1000, Master System (I, II) & Game Gear hardware models for 100% compatibility.
* updated to new Genesis Plus license (see http://cgfm2.emuviews.com/)
* removed DOS port
* various code cleanup.
[Gamecube/Wii]
---------------
* IMPORTANT: cheats, screenshots & save files are now stored in console-specific directories (ex: /snaps/md, /cheats/ms, /saves/gg, ...)
* added 8-bit Action Replay & Game Genie codes support (for Master System & Game Gear games).
* improved audio/video synchronization for PAL games in 50Hz TV modes (now use VSYNC like NTSC games in 60hz modes).
* improved gun cursor positioning accuracy.
* improved horizontal scaling & screenshots rendering in H32 mode.
* fixed a bug with ROM file extension handling that would affect cheats, snapshots, sram & savestate files.
* removed ARAM/injected ROM support (unused).
* removed WPAD_ and PAD_ update from VSYNC callback.
* increased GCC inlining limits for some speed improvment.
* compiled with devkitPPC r24 & libogc 1.8.7.
2011-08-07 19:49:46 +02:00
|
|
|
* - Redistributions may not be sold, nor may they be used in a commercial
|
|
|
|
* product or activity.
|
2011-07-14 00:49:52 +02:00
|
|
|
*
|
----------------------
Genesis Plus GX 1.6.0
----------------------
[Core/Sound]
---------------
* added YM2413 emulation in Master System compatibility mode.
* fixed SN76489 noise boost initialization.
* minor YM2612 core optimizations.
[Core/VDP]
---------------
* added accurate emulation of SG-1000, Master System (315-5124, 315-5246) & Game Gear VDP.
* added support for all TMS9918 rendering modes.
* improved Mega Drive VDP timings accuracy in Master System Compatibility mode.
* fixed color palette initialization.
* fixed shifted sprites rendering in Mode 4.
* modified pixel rendering support (pixel depth is now forced at compilation time).
[Core/CPU]
---------------
* optimized 68k core (rewrote 68k interrupt handling, removed multiple CPU types support & unused code) for 5~8% speed improvment
[Core/IO]
---------------
* added accurate emulation of Master System (315-5216, 315-5237, 315-5297) & Game Gear I/O controllers.
* added Terebi Oekaki tablet emulation.
* improved Mouse emulation (fixes mouse support in Cannon Fodder).
* improved Justifier emulation (fixes gun support in Lethal Enforcers 2).
* improved 6-Buttons control pad emulation (fixes Duke Nukem 3D)
* modified lightgun emulation to use common key inputs for all devices.
* 2-buttons controller is now picked by default for Master System games.
[Core/MD]
---------------
* added copy-protection hardware emulation for some new dumped games (Tiny Toon Adventures 3, Mighty Morphin Power Rangers & The Battle of Red Cliffs).
* added Game Toshokan in EEPROM database (verified on real cartridge).
* fixed Micro Machines 2 - Turbo Tournament EEPROM size (verified on real cartridge).
* modified SRAM banswitch hardware emulation to be more compatible with some hacks.
[Core/MS]
---------------
* added Cyborg Z to Korean mapper database.
[Core/GG]
---------------
* added 93C46 EEPROM emulation (Majors Pro Baseball, World Series Baseball & World Series Baseball 95).
[Core/General]
---------------
* added support for .mdx ROM format.
* added Game Gear & SG-1000 ROM support.
* added accurate emulation of SG-1000, Master System (I, II) & Game Gear hardware models for 100% compatibility.
* updated to new Genesis Plus license (see http://cgfm2.emuviews.com/)
* removed DOS port
* various code cleanup.
[Gamecube/Wii]
---------------
* IMPORTANT: cheats, screenshots & save files are now stored in console-specific directories (ex: /snaps/md, /cheats/ms, /saves/gg, ...)
* added 8-bit Action Replay & Game Genie codes support (for Master System & Game Gear games).
* improved audio/video synchronization for PAL games in 50Hz TV modes (now use VSYNC like NTSC games in 60hz modes).
* improved gun cursor positioning accuracy.
* improved horizontal scaling & screenshots rendering in H32 mode.
* fixed a bug with ROM file extension handling that would affect cheats, snapshots, sram & savestate files.
* removed ARAM/injected ROM support (unused).
* removed WPAD_ and PAD_ update from VSYNC callback.
* increased GCC inlining limits for some speed improvment.
* compiled with devkitPPC r24 & libogc 1.8.7.
2011-08-07 19:49:46 +02:00
|
|
|
* - Redistributions that are modified from the original source must include the
|
|
|
|
* complete source code, including the source code for all components used by a
|
|
|
|
* binary built from the modified sources. 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.
|
|
|
|
*
|
|
|
|
* - Redistributions must reproduce the above copyright notice, this list of
|
|
|
|
* conditions and the following disclaimer in the documentation and/or other
|
|
|
|
* materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
2011-07-14 00:49:52 +02:00
|
|
|
*
|
|
|
|
****************************************************************************************/
|
|
|
|
|
|
|
|
#include "shared.h"
|
2012-10-13 19:01:31 +02:00
|
|
|
#include "blip_buf.h"
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
/* FM output buffer (large enough to hold a whole frame at original chips rate) */
|
2017-09-23 18:47:50 +02:00
|
|
|
#ifdef HAVE_YM3438_CORE
|
2017-09-23 05:52:45 +02:00
|
|
|
static int fm_buffer[1080 * 2 * 24];
|
2017-09-23 18:47:50 +02:00
|
|
|
#else
|
|
|
|
static int fm_buffer[1080 * 2];
|
|
|
|
#endif
|
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
static int fm_last[2];
|
|
|
|
static int *fm_ptr;
|
|
|
|
|
|
|
|
/* Cycle-accurate FM samples */
|
|
|
|
static uint32 fm_cycles_ratio;
|
|
|
|
static uint32 fm_cycles_start;
|
|
|
|
static uint32 fm_cycles_count;
|
2011-07-14 00:49:52 +02:00
|
|
|
|
|
|
|
/* YM chip function pointers */
|
|
|
|
static void (*YM_Reset)(void);
|
2011-09-25 12:21:44 +02:00
|
|
|
static void (*YM_Update)(int *buffer, int length);
|
2011-07-14 00:49:52 +02:00
|
|
|
static void (*YM_Write)(unsigned int a, unsigned int v);
|
2017-09-23 05:52:45 +02:00
|
|
|
static unsigned int (*YM_Read)(unsigned int a);
|
|
|
|
|
2017-09-23 13:26:26 +02:00
|
|
|
#ifdef HAVE_YM3438_CORE
|
2017-09-23 05:52:45 +02:00
|
|
|
static ym3438_t ym3438;
|
2017-12-22 20:37:58 +01:00
|
|
|
static short ym3438_accm[24][2];
|
2017-09-23 05:52:45 +02:00
|
|
|
static int ym3438_sample[2];
|
|
|
|
static unsigned int ym3438_cycles;
|
|
|
|
|
|
|
|
void YM3438_Reset(void)
|
|
|
|
{
|
2017-09-29 11:01:03 +02:00
|
|
|
OPN2_Reset(&ym3438);
|
2017-09-23 05:52:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void YM3438_Update(int *buffer, int length)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
OPN2_Clock(&ym3438, ym3438_accm[ym3438_cycles]);
|
|
|
|
ym3438_cycles = (ym3438_cycles + 1) % 24;
|
|
|
|
if (ym3438_cycles == 0)
|
|
|
|
{
|
|
|
|
ym3438_sample[0] = 0;
|
|
|
|
ym3438_sample[1] = 0;
|
|
|
|
for (j = 0; j < 24; j++)
|
|
|
|
{
|
|
|
|
ym3438_sample[0] += ym3438_accm[j][0];
|
|
|
|
ym3438_sample[1] += ym3438_accm[j][1];
|
|
|
|
}
|
|
|
|
}
|
2017-09-28 18:45:49 +02:00
|
|
|
*buffer++ = ym3438_sample[0] * 11;
|
|
|
|
*buffer++ = ym3438_sample[1] * 11;
|
2017-09-23 05:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void YM3438_Write(unsigned int a, unsigned int v)
|
|
|
|
{
|
|
|
|
OPN2_Write(&ym3438, a, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int YM3438_Read(unsigned int a)
|
|
|
|
{
|
2017-09-23 13:26:26 +02:00
|
|
|
return OPN2_Read(&ym3438, a);
|
2017-09-23 05:52:45 +02:00
|
|
|
}
|
2017-09-23 13:26:26 +02:00
|
|
|
#endif
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
/* Run FM chip until required M-cycles */
|
2012-01-31 23:50:54 +01:00
|
|
|
INLINE void fm_update(unsigned int cycles)
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
|
|
|
if (cycles > fm_cycles_count)
|
|
|
|
{
|
2012-10-13 19:01:31 +02:00
|
|
|
/* number of samples to run */
|
2012-01-15 20:57:59 +01:00
|
|
|
unsigned int samples = (cycles - fm_cycles_count + fm_cycles_ratio - 1) / fm_cycles_ratio;
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
/* run FM chip to sample buffer */
|
|
|
|
YM_Update(fm_ptr, samples);
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
/* update FM buffer pointer */
|
|
|
|
fm_ptr += (samples << 1);
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
/* update FM cycle counter */
|
|
|
|
fm_cycles_count += samples * fm_cycles_ratio;
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
void sound_init( void )
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
2012-10-13 19:01:31 +02:00
|
|
|
/* Initialize FM chip */
|
----------------------
Genesis Plus GX 1.6.0
----------------------
[Core/Sound]
---------------
* added YM2413 emulation in Master System compatibility mode.
* fixed SN76489 noise boost initialization.
* minor YM2612 core optimizations.
[Core/VDP]
---------------
* added accurate emulation of SG-1000, Master System (315-5124, 315-5246) & Game Gear VDP.
* added support for all TMS9918 rendering modes.
* improved Mega Drive VDP timings accuracy in Master System Compatibility mode.
* fixed color palette initialization.
* fixed shifted sprites rendering in Mode 4.
* modified pixel rendering support (pixel depth is now forced at compilation time).
[Core/CPU]
---------------
* optimized 68k core (rewrote 68k interrupt handling, removed multiple CPU types support & unused code) for 5~8% speed improvment
[Core/IO]
---------------
* added accurate emulation of Master System (315-5216, 315-5237, 315-5297) & Game Gear I/O controllers.
* added Terebi Oekaki tablet emulation.
* improved Mouse emulation (fixes mouse support in Cannon Fodder).
* improved Justifier emulation (fixes gun support in Lethal Enforcers 2).
* improved 6-Buttons control pad emulation (fixes Duke Nukem 3D)
* modified lightgun emulation to use common key inputs for all devices.
* 2-buttons controller is now picked by default for Master System games.
[Core/MD]
---------------
* added copy-protection hardware emulation for some new dumped games (Tiny Toon Adventures 3, Mighty Morphin Power Rangers & The Battle of Red Cliffs).
* added Game Toshokan in EEPROM database (verified on real cartridge).
* fixed Micro Machines 2 - Turbo Tournament EEPROM size (verified on real cartridge).
* modified SRAM banswitch hardware emulation to be more compatible with some hacks.
[Core/MS]
---------------
* added Cyborg Z to Korean mapper database.
[Core/GG]
---------------
* added 93C46 EEPROM emulation (Majors Pro Baseball, World Series Baseball & World Series Baseball 95).
[Core/General]
---------------
* added support for .mdx ROM format.
* added Game Gear & SG-1000 ROM support.
* added accurate emulation of SG-1000, Master System (I, II) & Game Gear hardware models for 100% compatibility.
* updated to new Genesis Plus license (see http://cgfm2.emuviews.com/)
* removed DOS port
* various code cleanup.
[Gamecube/Wii]
---------------
* IMPORTANT: cheats, screenshots & save files are now stored in console-specific directories (ex: /snaps/md, /cheats/ms, /saves/gg, ...)
* added 8-bit Action Replay & Game Genie codes support (for Master System & Game Gear games).
* improved audio/video synchronization for PAL games in 50Hz TV modes (now use VSYNC like NTSC games in 60hz modes).
* improved gun cursor positioning accuracy.
* improved horizontal scaling & screenshots rendering in H32 mode.
* fixed a bug with ROM file extension handling that would affect cheats, snapshots, sram & savestate files.
* removed ARAM/injected ROM support (unused).
* removed WPAD_ and PAD_ update from VSYNC callback.
* increased GCC inlining limits for some speed improvment.
* compiled with devkitPPC r24 & libogc 1.8.7.
2011-08-07 19:49:46 +02:00
|
|
|
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
|
|
|
/* YM2612 */
|
2017-10-07 00:46:31 +02:00
|
|
|
#ifdef HAVE_YM3438_CORE
|
2017-09-23 13:26:26 +02:00
|
|
|
if (config.ym3438)
|
2017-09-23 05:52:45 +02:00
|
|
|
{
|
2017-09-23 13:26:26 +02:00
|
|
|
/* Nuked OPN2 */
|
2017-09-23 05:52:45 +02:00
|
|
|
memset(&ym3438, 0, sizeof(ym3438));
|
|
|
|
memset(&ym3438_sample, 0, sizeof(ym3438_sample));
|
|
|
|
memset(&ym3438_accm, 0, sizeof(ym3438_accm));
|
|
|
|
YM_Reset = YM3438_Reset;
|
|
|
|
YM_Update = YM3438_Update;
|
|
|
|
YM_Write = YM3438_Write;
|
|
|
|
YM_Read = YM3438_Read;
|
|
|
|
|
|
|
|
/* chip is running at VCLK / 6 = MCLK / 7 / 6 */
|
|
|
|
fm_cycles_ratio = 6 * 7;
|
|
|
|
}
|
|
|
|
else
|
2017-10-07 00:46:31 +02:00
|
|
|
#endif
|
2017-09-23 05:52:45 +02:00
|
|
|
{
|
2017-09-23 13:26:26 +02:00
|
|
|
/* MAME */
|
2017-09-23 05:52:45 +02:00
|
|
|
YM2612Init();
|
|
|
|
YM2612Config(config.dac_bits);
|
|
|
|
YM_Reset = YM2612ResetChip;
|
|
|
|
YM_Update = YM2612Update;
|
|
|
|
YM_Write = YM2612Write;
|
|
|
|
YM_Read = YM2612Read;
|
|
|
|
|
|
|
|
/* chip is running at VCLK / 144 = MCLK / 7 / 144 */
|
|
|
|
fm_cycles_ratio = 144 * 7;
|
|
|
|
}
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* YM2413 */
|
2012-10-13 19:01:31 +02:00
|
|
|
YM2413Init();
|
2011-07-14 00:49:52 +02:00
|
|
|
YM_Reset = YM2413ResetChip;
|
|
|
|
YM_Update = YM2413Update;
|
|
|
|
YM_Write = YM2413Write;
|
2017-09-23 05:52:45 +02:00
|
|
|
YM_Read = NULL;
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2016-12-18 23:36:59 +01:00
|
|
|
/* chip is running at ZCLK / 72 = MCLK / 15 / 72 */
|
2012-10-13 19:01:31 +02:00
|
|
|
fm_cycles_ratio = 72 * 15;
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
/* Initialize PSG chip */
|
2016-12-18 23:36:59 +01:00
|
|
|
psg_init((system_hw == SYSTEM_SG) ? PSG_DISCRETE : PSG_INTEGRATED);
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void sound_reset(void)
|
|
|
|
{
|
2012-10-13 19:01:31 +02:00
|
|
|
/* reset sound chips */
|
2011-07-14 00:49:52 +02:00
|
|
|
YM_Reset();
|
2016-12-18 23:36:59 +01:00
|
|
|
psg_reset();
|
|
|
|
psg_config(0, config.psg_preamp, 0xff);
|
2012-10-13 19:01:31 +02:00
|
|
|
|
|
|
|
/* reset FM buffer ouput */
|
|
|
|
fm_last[0] = fm_last[1] = 0;
|
|
|
|
|
|
|
|
/* reset FM buffer pointer */
|
|
|
|
fm_ptr = fm_buffer;
|
|
|
|
|
|
|
|
/* reset FM cycle counters */
|
|
|
|
fm_cycles_start = fm_cycles_count = 0;
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
int sound_update(unsigned int cycles)
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
2016-12-18 23:09:16 +01:00
|
|
|
int prev_l, prev_r, preamp, time, l, r, *ptr;
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2016-12-18 23:36:59 +01:00
|
|
|
/* Run PSG chip until end of frame */
|
|
|
|
psg_end_frame(cycles);
|
|
|
|
|
|
|
|
/* Run FM chip until end of frame */
|
2012-10-13 19:01:31 +02:00
|
|
|
fm_update(cycles);
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2016-12-18 23:09:16 +01:00
|
|
|
/* FM output pre-amplification */
|
2012-10-13 19:01:31 +02:00
|
|
|
preamp = config.fm_preamp;
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
/* FM frame initial timestamp */
|
|
|
|
time = fm_cycles_start;
|
|
|
|
|
|
|
|
/* Restore last FM outputs from previous frame */
|
2016-12-18 23:09:16 +01:00
|
|
|
prev_l = fm_last[0];
|
|
|
|
prev_r = fm_last[1];
|
2012-10-13 19:01:31 +02:00
|
|
|
|
|
|
|
/* FM buffer start pointer */
|
|
|
|
ptr = fm_buffer;
|
|
|
|
|
|
|
|
/* flush FM samples */
|
|
|
|
if (config.hq_fm)
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
2012-10-13 19:01:31 +02:00
|
|
|
/* high-quality Band-Limited synthesis */
|
|
|
|
do
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
2016-12-18 23:09:16 +01:00
|
|
|
/* left & right channels */
|
|
|
|
l = ((*ptr++ * preamp) / 100);
|
|
|
|
r = ((*ptr++ * preamp) / 100);
|
|
|
|
blip_add_delta(snd.blips[0], time, l-prev_l, r-prev_r);
|
|
|
|
prev_l = l;
|
|
|
|
prev_r = r;
|
2012-10-13 19:01:31 +02:00
|
|
|
|
|
|
|
/* increment time counter */
|
|
|
|
time += fm_cycles_ratio;
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
2012-10-13 19:01:31 +02:00
|
|
|
while (time < cycles);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* faster Linear Interpolation */
|
|
|
|
do
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
2016-12-18 23:09:16 +01:00
|
|
|
/* left & right channels */
|
|
|
|
l = ((*ptr++ * preamp) / 100);
|
|
|
|
r = ((*ptr++ * preamp) / 100);
|
|
|
|
blip_add_delta_fast(snd.blips[0], time, l-prev_l, r-prev_r);
|
|
|
|
prev_l = l;
|
|
|
|
prev_r = r;
|
2012-10-13 19:01:31 +02:00
|
|
|
|
|
|
|
/* increment time counter */
|
|
|
|
time += fm_cycles_ratio;
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
2012-10-13 19:01:31 +02:00
|
|
|
while (time < cycles);
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
2012-10-13 19:01:31 +02:00
|
|
|
|
|
|
|
/* reset FM buffer pointer */
|
|
|
|
fm_ptr = fm_buffer;
|
|
|
|
|
|
|
|
/* save last FM output for next frame */
|
2016-12-18 23:09:16 +01:00
|
|
|
fm_last[0] = prev_l;
|
|
|
|
fm_last[1] = prev_r;
|
2012-10-13 19:01:31 +02:00
|
|
|
|
|
|
|
/* adjust FM cycle counters for next frame */
|
|
|
|
fm_cycles_count = fm_cycles_start = time - cycles;
|
2016-12-18 23:09:16 +01:00
|
|
|
|
|
|
|
/* end of blip buffer time frame */
|
|
|
|
blip_end_frame(snd.blips[0], cycles);
|
2012-10-13 19:01:31 +02:00
|
|
|
|
|
|
|
/* return number of available samples */
|
2016-12-18 23:09:16 +01:00
|
|
|
return blip_samples_avail(snd.blips[0]);
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int sound_context_save(uint8 *state)
|
|
|
|
{
|
|
|
|
int bufferptr = 0;
|
|
|
|
|
----------------------
Genesis Plus GX 1.6.0
----------------------
[Core/Sound]
---------------
* added YM2413 emulation in Master System compatibility mode.
* fixed SN76489 noise boost initialization.
* minor YM2612 core optimizations.
[Core/VDP]
---------------
* added accurate emulation of SG-1000, Master System (315-5124, 315-5246) & Game Gear VDP.
* added support for all TMS9918 rendering modes.
* improved Mega Drive VDP timings accuracy in Master System Compatibility mode.
* fixed color palette initialization.
* fixed shifted sprites rendering in Mode 4.
* modified pixel rendering support (pixel depth is now forced at compilation time).
[Core/CPU]
---------------
* optimized 68k core (rewrote 68k interrupt handling, removed multiple CPU types support & unused code) for 5~8% speed improvment
[Core/IO]
---------------
* added accurate emulation of Master System (315-5216, 315-5237, 315-5297) & Game Gear I/O controllers.
* added Terebi Oekaki tablet emulation.
* improved Mouse emulation (fixes mouse support in Cannon Fodder).
* improved Justifier emulation (fixes gun support in Lethal Enforcers 2).
* improved 6-Buttons control pad emulation (fixes Duke Nukem 3D)
* modified lightgun emulation to use common key inputs for all devices.
* 2-buttons controller is now picked by default for Master System games.
[Core/MD]
---------------
* added copy-protection hardware emulation for some new dumped games (Tiny Toon Adventures 3, Mighty Morphin Power Rangers & The Battle of Red Cliffs).
* added Game Toshokan in EEPROM database (verified on real cartridge).
* fixed Micro Machines 2 - Turbo Tournament EEPROM size (verified on real cartridge).
* modified SRAM banswitch hardware emulation to be more compatible with some hacks.
[Core/MS]
---------------
* added Cyborg Z to Korean mapper database.
[Core/GG]
---------------
* added 93C46 EEPROM emulation (Majors Pro Baseball, World Series Baseball & World Series Baseball 95).
[Core/General]
---------------
* added support for .mdx ROM format.
* added Game Gear & SG-1000 ROM support.
* added accurate emulation of SG-1000, Master System (I, II) & Game Gear hardware models for 100% compatibility.
* updated to new Genesis Plus license (see http://cgfm2.emuviews.com/)
* removed DOS port
* various code cleanup.
[Gamecube/Wii]
---------------
* IMPORTANT: cheats, screenshots & save files are now stored in console-specific directories (ex: /snaps/md, /cheats/ms, /saves/gg, ...)
* added 8-bit Action Replay & Game Genie codes support (for Master System & Game Gear games).
* improved audio/video synchronization for PAL games in 50Hz TV modes (now use VSYNC like NTSC games in 60hz modes).
* improved gun cursor positioning accuracy.
* improved horizontal scaling & screenshots rendering in H32 mode.
* fixed a bug with ROM file extension handling that would affect cheats, snapshots, sram & savestate files.
* removed ARAM/injected ROM support (unused).
* removed WPAD_ and PAD_ update from VSYNC callback.
* increased GCC inlining limits for some speed improvment.
* compiled with devkitPPC r24 & libogc 1.8.7.
2011-08-07 19:49:46 +02:00
|
|
|
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
2017-10-07 00:46:31 +02:00
|
|
|
#ifdef HAVE_YM3438_CORE
|
2017-09-23 14:17:05 +02:00
|
|
|
save_param(&config.ym3438, sizeof(config.ym3438));
|
2017-09-23 13:26:26 +02:00
|
|
|
if (config.ym3438)
|
2017-09-23 05:52:45 +02:00
|
|
|
{
|
|
|
|
save_param(&ym3438, sizeof(ym3438));
|
|
|
|
save_param(&ym3438_accm, sizeof(ym3438_accm));
|
|
|
|
save_param(&ym3438_sample, sizeof(ym3438_sample));
|
|
|
|
save_param(&ym3438_cycles, sizeof(ym3438_cycles));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-23 14:17:05 +02:00
|
|
|
bufferptr += YM2612SaveContext(state + sizeof(config.ym3438));
|
|
|
|
YM2612Config(config.dac_bits);
|
2017-09-23 05:52:45 +02:00
|
|
|
}
|
2017-10-07 00:46:31 +02:00
|
|
|
#else
|
2017-09-23 14:17:05 +02:00
|
|
|
bufferptr = YM2612SaveContext(state);
|
2017-10-07 00:46:31 +02:00
|
|
|
#endif
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
save_param(YM2413GetContextPtr(),YM2413GetContextSize());
|
|
|
|
}
|
|
|
|
|
2016-12-18 23:36:59 +01:00
|
|
|
bufferptr += psg_context_save(&state[bufferptr]);
|
2012-10-13 19:01:31 +02:00
|
|
|
|
|
|
|
save_param(&fm_cycles_start,sizeof(fm_cycles_start));
|
2011-07-14 00:49:52 +02:00
|
|
|
|
|
|
|
return bufferptr;
|
|
|
|
}
|
|
|
|
|
2012-01-15 20:57:59 +01:00
|
|
|
int sound_context_load(uint8 *state)
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
|
|
|
int bufferptr = 0;
|
|
|
|
|
2012-01-15 20:57:59 +01:00
|
|
|
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
2017-10-07 00:46:31 +02:00
|
|
|
#ifdef HAVE_YM3438_CORE
|
|
|
|
uint8 config_ym3438;
|
2017-09-23 14:17:05 +02:00
|
|
|
load_param(&config_ym3438, sizeof(config_ym3438));
|
|
|
|
if (config_ym3438)
|
2017-09-23 05:52:45 +02:00
|
|
|
{
|
|
|
|
load_param(&ym3438, sizeof(ym3438));
|
|
|
|
load_param(&ym3438_accm, sizeof(ym3438_accm));
|
|
|
|
load_param(&ym3438_sample, sizeof(ym3438_sample));
|
|
|
|
load_param(&ym3438_cycles, sizeof(ym3438_cycles));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-07 00:46:31 +02:00
|
|
|
bufferptr += YM2612LoadContext(state + sizeof(config_ym3438));
|
|
|
|
YM2612Config(config.dac_bits);
|
2017-09-23 05:52:45 +02:00
|
|
|
}
|
2017-10-07 00:46:31 +02:00
|
|
|
#else
|
2017-09-23 14:17:05 +02:00
|
|
|
bufferptr = YM2612LoadContext(state);
|
|
|
|
YM2612Config(config.dac_bits);
|
2017-10-07 00:46:31 +02:00
|
|
|
#endif
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
load_param(YM2413GetContextPtr(),YM2413GetContextSize());
|
|
|
|
}
|
|
|
|
|
2016-12-18 23:36:59 +01:00
|
|
|
bufferptr += psg_context_load(&state[bufferptr]);
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
load_param(&fm_cycles_start,sizeof(fm_cycles_start));
|
|
|
|
fm_cycles_count = fm_cycles_start;
|
2011-07-14 00:49:52 +02:00
|
|
|
|
|
|
|
return bufferptr;
|
|
|
|
}
|
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
void fm_reset(unsigned int cycles)
|
2011-07-14 00:49:52 +02:00
|
|
|
{
|
2012-10-13 19:01:31 +02:00
|
|
|
/* synchronize FM chip with CPU */
|
2011-07-14 00:49:52 +02:00
|
|
|
fm_update(cycles);
|
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
/* reset FM chip */
|
2011-07-14 00:49:52 +02:00
|
|
|
YM_Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void fm_write(unsigned int cycles, unsigned int address, unsigned int data)
|
|
|
|
{
|
2017-09-23 05:52:45 +02:00
|
|
|
/* synchronize FM chip with CPU */
|
|
|
|
fm_update(cycles);
|
2012-10-13 19:01:31 +02:00
|
|
|
|
|
|
|
/* write FM register */
|
2011-07-14 00:49:52 +02:00
|
|
|
YM_Write(address, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int fm_read(unsigned int cycles, unsigned int address)
|
|
|
|
{
|
2012-10-13 19:01:31 +02:00
|
|
|
/* synchronize FM chip with CPU */
|
|
|
|
fm_update(cycles);
|
2011-07-14 00:49:52 +02:00
|
|
|
|
2012-10-13 19:01:31 +02:00
|
|
|
/* read FM status (YM2612 only) */
|
2017-09-23 05:52:45 +02:00
|
|
|
return YM_Read(address);
|
2011-07-14 00:49:52 +02:00
|
|
|
}
|