Commit 483e746a authored by ds22x's avatar ds22x
Browse files

Sync to upstream. More info in description.

parents d27b1cb3 86c46138
Pipeline #52755 passed with stages
in 1 minute and 56 seconds
......@@ -54,6 +54,7 @@ Genesis Plus GX 1.7.5 (xx/xx/xxxx) (Eke-Eke)
* added support for more X-in-1 pirate mappers
* added support for some new unlicensed games with copy protection (Thunderbolt II, Tom Clown, Chaoji Puke / Super Poker, Rock Heaven, Rock World)
* added support for Everdrive extended SSF mapper
* added support for MegaSD CD hardware overlay (MD+ hacks) and extended SSF2 / ROM write mappers
* added (very basic) emulation of Flashkit MD hardware
* added emulation of Micro Machines USA on-board TMSS bypass logic hardware
* added SRAM support for games larger than 8MB
......
No preview for this file type
No preview for this file type
......@@ -44,6 +44,7 @@
#include "shared.h"
#include "eeprom_i2c.h"
#include "eeprom_spi.h"
#include "megasd.h"
/* Cart database entry */
typedef struct
......@@ -518,6 +519,21 @@ void md_cart_init(void)
/* cartridge ROM mapping is reinitialized on /VRES */
cart.hw.bankshift = 1;
}
else if ((strstr(rominfo.consoletype,"SEGA SSF2") != NULL) && (cart.romsize <= 0x800000))
{
/* MegaSD enhanced SSF2 mapper (max. 8MB ROM) */
cart.special |= HW_MEGASD;
cart.hw.time_w = megasd_enhanced_ssf2_mapper_w;
/* cartridge ROM mapping is reinitialized on /VRES */
cart.hw.bankshift = 1;
}
else if ((strstr(rominfo.consoletype,"SEGA MEGASD") != NULL) && (cart.romsize <= 0x400000))
{
/* MegaSD ROM write mapper (max. 4MB ROM) */
cart.special |= HW_MEGASD;
cart.hw.time_w = megasd_rom_mapper_w;
}
else if (strstr(rominfo.domestic,"SUPER STREET FIGHTER2"))
{
/* SSF2 mapper */
......@@ -760,6 +776,26 @@ void md_cart_init(void)
break;
}
}
/**********************************************
MEGASD ADD-ON
***********************************************/
/* enable MegaSD overlay for cartridge ROM (max. 8MB) when Mega CD hardware is disabled and either MegaSD add-on is forced enabled or automatic add-on detection is enabled and MegaSD compatible disc image is loaded */
if ((cart.romsize <= 0x800000) && (system_hw == SYSTEM_MD) && ((config.add_on == HW_ADDON_MEGASD) || ((config.add_on | cdd.loaded) == HW_ADDON_MEGASD)))
{
cart.special |= HW_MEGASD;
}
/* force Mega CD sound hardware initialization when MegaSD overlay is enabled (if not already initialized) */
if ((cart.special & HW_MEGASD) && !snd.blips[1] && !snd.blips[2])
{
/* allocate blip buffers for PCM and CD-DA audio streams */
snd.blips[1] = blip_new(snd.sample_rate / 10);
snd.blips[2] = blip_new(snd.sample_rate / 10);
/* initialize PCM and CD-DA audio */
audio_set_rate(snd.sample_rate, snd.frame_rate);
}
}
/* hardware that need to be reseted on power on */
......@@ -775,7 +811,13 @@ void md_cart_reset(int hard_reset)
m68k.memory_map[i].base = cart.rom + ((i<<16) & cart.mask);
}
}
/* MegaSD hardware */
if (cart.special & HW_MEGASD)
{
megasd_reset();
}
/* SVP chip */
if (svp)
{
......@@ -828,7 +870,7 @@ int md_cart_context_save(uint8 *state)
{
/* get base address */
base = m68k.memory_map[i].base;
if (base == sram.sram)
{
/* SRAM */
......@@ -857,6 +899,12 @@ int md_cart_context_save(uint8 *state)
save_param(&svp->ssp1601,sizeof(ssp1601_t));
}
/* MegaSD hardware */
if (cart.special & HW_MEGASD)
{
bufferptr += megasd_context_save(&state[bufferptr]);
}
return bufferptr;
}
......@@ -913,6 +961,12 @@ int md_cart_context_load(uint8 *state)
load_param(&svp->ssp1601,sizeof(ssp1601_t));
}
/* MegaSD hardware */
if (cart.special & HW_MEGASD)
{
bufferptr += megasd_context_load(&state[bufferptr]);
}
return bufferptr;
}
......
......@@ -55,9 +55,16 @@
#define TYPE_AR 0x02 /* (Pro) Action Replay */
#define TYPE_SK 0x03 /* Sonic & Knuckles */
/* CD hardware add-on (MD mode) */
#define HW_ADDON_AUTO 0x00
#define HW_ADDON_MEGACD 0x01
#define HW_ADDON_MEGASD 0x02
#define HW_ADDON_NONE 0x03
/* Special hardware (0x01 & 0x02 reserved for Master System 3-D glasses & Terebi Oekaki) */
#define HW_J_CART 0x04
#define HW_LOCK_ON 0x08
#define HW_MEGASD 0x10
/* Cartridge extra hardware */
typedef struct
......
This diff is collapsed.
/****************************************************************************
* Genesis Plus
* MegaSD flashcart CD hardware interface overlay & enhanced ROM mappers
*
* Copyright (C) 2020-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
*
* - Redistributions may not be sold, nor may they be used in a commercial
* product or activity.
*
* - 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.
*
****************************************************************************************/
#ifndef _MEGASD_H_
#define _MEGASD_H_
#include "shared.h"
extern void megasd_reset(void);
extern void megasd_rom_mapper_w(unsigned int address, unsigned int data);
extern void megasd_enhanced_ssf2_mapper_w(unsigned int address, unsigned int data);
extern void megasd_update_cdda(unsigned int samples);
extern int megasd_context_save(uint8 *state);
extern int megasd_context_load(uint8 *state);
#endif
This diff is collapsed.
......@@ -2,7 +2,7 @@
* Genesis Plus
* CD drive processor & CD-DA fader
*
* Copyright (C) 2012-2020 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2012-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......@@ -86,6 +86,8 @@ typedef struct
int start;
int end;
int type;
int loopEnabled;
int loopOffset;
} track_t;
/* CD TOC */
......@@ -127,17 +129,17 @@ typedef struct
chd_t chd;
#endif
int16 audio[2];
int audioSampleOffset;
} cdd_t;
/* Function prototypes */
extern void cdd_init(int samplerate);
extern void cdd_reset(void);
extern int cdd_context_save(uint8 *state);
extern int cdd_context_load(uint8 *state);
extern int cdd_context_load(uint8 *state, char *version);
extern int cdd_load(char *filename, char *header);
extern void cdd_unload(void);
extern void cdd_read_data(uint8 *dst, uint8 *subheader);
extern void cdd_seek_audio(int index, int lba);
extern void cdd_read_audio(unsigned int samples);
extern void cdd_update(void);
extern void cdd_process(void);
......
......@@ -2,7 +2,7 @@
* Genesis Plus
* PCM sound chip (315-5476A) (RF5C164 compatible)
*
* Copyright (C) 2012-2016 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2012-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......@@ -281,10 +281,10 @@ void pcm_update(unsigned int samples)
pcm.cycles = 0;
}
void pcm_write(unsigned int address, unsigned char data)
void pcm_write(unsigned int address, unsigned char data, unsigned int cycles)
{
/* synchronize PCM chip with SUB-CPU */
int clocks = s68k.cycles - pcm.cycles;
/* synchronize PCM chip with CPU */
int clocks = cycles - pcm.cycles;
if (clocks > 0)
{
/* number of internal clocks (samples) to run */
......@@ -405,10 +405,10 @@ void pcm_write(unsigned int address, unsigned char data)
}
}
unsigned char pcm_read(unsigned int address)
unsigned char pcm_read(unsigned int address, unsigned int cycles)
{
/* synchronize PCM chip with SUB-CPU */
int clocks = s68k.cycles - pcm.cycles;
int clocks = cycles - pcm.cycles;
if (clocks > 0)
{
/* number of internal clocks (samples) to run */
......
......@@ -2,7 +2,7 @@
* Genesis Plus
* PCM sound chip (315-5476A) (RF5C164 compatible)
*
* Copyright (C) 2012-2016 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2012-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......@@ -70,8 +70,8 @@ extern void pcm_reset(void);
extern int pcm_context_save(uint8 *state);
extern int pcm_context_load(uint8 *state);
extern void pcm_update(unsigned int samples);
extern void pcm_write(unsigned int address, unsigned char data);
extern unsigned char pcm_read(unsigned int address);
extern void pcm_write(unsigned int address, unsigned char data, unsigned int cycles);
extern unsigned char pcm_read(unsigned int address, unsigned int cycles);
extern void pcm_ram_dma_w(unsigned int words);
#endif
......@@ -2,7 +2,7 @@
* Genesis Plus
* Mega CD / Sega CD hardware
*
* Copyright (C) 2012-2020 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2012-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......@@ -484,7 +484,7 @@ static unsigned int scd_read_byte(unsigned int address)
/* get /LDS only */
if (address & 1)
{
return pcm_read((address >> 1) & 0x1fff);
return pcm_read((address >> 1) & 0x1fff, s68k.cycles);
}
return s68k_read_bus_8(address);
......@@ -603,7 +603,7 @@ static unsigned int scd_read_word(unsigned int address)
if (!(address & 0x8000))
{
/* get /LDS only */
return pcm_read((address >> 1) & 0x1fff);
return pcm_read((address >> 1) & 0x1fff, s68k.cycles);
}
#ifdef LOG_SCD
......@@ -766,7 +766,7 @@ static void scd_write_byte(unsigned int address, unsigned int data)
/* get /LDS only */
if (address & 1)
{
pcm_write((address >> 1) & 0x1fff, data);
pcm_write((address >> 1) & 0x1fff, data, s68k.cycles);
return;
}
......@@ -1030,7 +1030,7 @@ static void scd_write_word(unsigned int address, unsigned int data)
if (!(address & 0x8000))
{
/* get /LDS only */
pcm_write((address >> 1) & 0x1fff, data);
pcm_write((address >> 1) & 0x1fff, data & 0xff, s68k.cycles);
return;
}
......@@ -1856,7 +1856,7 @@ int scd_context_save(uint8 *state)
return bufferptr;
}
int scd_context_load(uint8 *state)
int scd_context_load(uint8 *state, char *version)
{
int i;
uint16 tmp16;
......@@ -1878,7 +1878,7 @@ int scd_context_load(uint8 *state)
bufferptr += cdc_context_load(&state[bufferptr]);
/* CD Drive processor */
bufferptr += cdd_context_load(&state[bufferptr]);
bufferptr += cdd_context_load(&state[bufferptr], version);
/* PCM chip */
bufferptr += pcm_context_load(&state[bufferptr]);
......
......@@ -2,7 +2,7 @@
* Genesis Plus
* Mega CD / Sega CD hardware
*
* Copyright (C) 2012-2020 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2012-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......@@ -87,7 +87,7 @@ extern void scd_init(void);
extern void scd_reset(int hard);
extern void scd_update(unsigned int cycles);
extern void scd_end_frame(unsigned int cycles);
extern int scd_context_load(uint8 *state);
extern int scd_context_load(uint8 *state, char *version);
extern int scd_context_save(uint8 *state);
extern int scd_68k_irq_ack(int level);
extern void prg_ram_dma_w(unsigned int words);
......
......@@ -3,7 +3,7 @@
* ROM Loading Support
*
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2007-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......@@ -58,20 +58,21 @@
#define ROMMEMO 456
#define ROMCOUNTRY 496
#define P3BUTTONS 1
#define P6BUTTONS 2
#define PKEYBOARD 4
#define PPRINTER 8
#define PBALL 16
#define PFLOPPY 32
#define PACTIVATOR 64
#define PTEAMPLAYER 128
#define PMSYSTEMPAD 256
#define PSERIAL 512
#define PTABLET 1024
#define PPADDLE 2048
#define PCDROM 4096
#define PMOUSE 8192
#define P3BUTTONS 0x0001
#define P6BUTTONS 0x0002
#define PKEYBOARD 0x0004
#define PPRINTER 0x0008
#define PBALL 0x0010
#define PFLOPPY 0x0020
#define PACTIVATOR 0x0040
#define PTEAMPLAYER 0x0080
#define PMSYSTEMPAD 0x0100
#define PSERIAL 0x0200
#define PTABLET 0x0400
#define PPADDLE 0x0800
#define PCDROM 0x1000
#define PMOUSE 0x2000
#define PMENACER 0x4000
#define MAXCOMPANY 64
#define MAXPERIPHERALS 15
......@@ -288,7 +289,7 @@ void getrominfo(char *romheader)
/* Supported peripherals */
rominfo.peripherals = 0;
for (i = 0; i < 14; i++)
for (j=0; j < 14; j++)
for (j=0; j < MAXPERIPHERALS; j++)
if (romheader[ROMIOSUPPORT+i] == peripheralinfo[j].pID[0])
rominfo.peripherals |= (1 << j);
}
......@@ -582,8 +583,6 @@ int load_rom(char *filename)
/* enable CD hardware */
system_hw = SYSTEM_MCD;
/* boot from CD hardware */
scd.cartridge.boot = 0x00;
}
else
{
......@@ -715,10 +714,10 @@ int load_rom(char *filename)
/* Save auto-detected system hardware */
romtype = system_hw;
/* CD image file */
if (system_hw == SYSTEM_MCD)
{
{
/* try to load CD BOOTROM for selected region */
if (!load_bios(SYSTEM_MCD))
{
......@@ -728,6 +727,9 @@ int load_rom(char *filename)
/* error booting from CD */
return (0);
}
/* boot from CD hardware */
scd.cartridge.boot = 0x00;
}
/* CD BOOTROM */
......@@ -749,44 +751,26 @@ int load_rom(char *filename)
system_bios = (system_bios & 0xf0) | (region_code >> 4);
}
/* ROM cartridge (max. 8MB) with CD loaded */
else if ((cart.romsize <= 0x800000) && cdd.loaded)
{
/* try to load CD BOOTROM */
if (load_bios(SYSTEM_MCD))
{
/* enable CD hardware */
system_hw = SYSTEM_MCD;
/* boot from cartridge */
scd.cartridge.boot = 0x40;
}
else
{
/* unmount CD image */
cdd_unload();
}
}
/* ROM cartridge with CD support */
else if ((strstr(rominfo.domestic,"FLUX") != NULL) ||
(strstr(rominfo.domestic,"WONDER LIBRARY") != NULL) ||
(strstr(rominfo.product,"T-5740") != NULL))
/* 16-bit ROM cartridge (max. 8MB) with optional CD hardware add-on support enabled */
else if ((system_hw == SYSTEM_MD) && (cart.romsize <= 0x800000) && (config.add_on != HW_ADDON_NONE))
{
/* check if console hardware is set to AUTO */
if (!config.system)
if ((rominfo.peripherals & PCDROM) || (strstr(rominfo.domestic,"FLUX") != NULL) ||
(config.add_on == HW_ADDON_MEGACD) || ((config.add_on | cdd.loaded) == HW_ADDON_MEGACD))
{
/* try to load CD BOOTROM */
/* try to load CD BOOTROM for selected region */
if (load_bios(SYSTEM_MCD))
{
char fname[256];
int len = strlen(filename);
/* automatically try to load associated .iso file */
while ((len && (filename[len] != '.')) || (len > 251)) len--;
strncpy(fname, filename, len);
strcpy(&fname[len], ".iso");
cdd_load(fname, (char *)cdc.ram);
/* automatically try to load associated .iso file if no CD image loaded yet */
if (!cdd.loaded)
{
char fname[256];
int len = strlen(filename);
while ((len && (filename[len] != '.')) || (len > 251)) len--;
strncpy(fname, filename, len);
strcpy(&fname[len], ".iso");
fname[len+4] = 0;
cdd_load(fname, (char *)cdc.ram);
}
/* enable CD hardware */
system_hw = SYSTEM_MCD;
......@@ -794,6 +778,11 @@ int load_rom(char *filename)
/* boot from cartridge */
scd.cartridge.boot = 0x40;
}
else
{
/* unmount any loaded CD image */
cdd_unload();
}
}
}
......
......@@ -3,7 +3,7 @@
* ROM Loading Support
*
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
* Copyright (C) 2007-2020 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2007-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......
......@@ -2,7 +2,7 @@
* Genesis Plus
* Savestate support
*
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2007-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......@@ -154,7 +154,7 @@ int state_load(unsigned char *state)
load_param(&tmp32, 4); m68k_set_reg(M68K_REG_USP,tmp32);
load_param(&tmp32, 4); m68k_set_reg(M68K_REG_ISP,tmp32);
load_param(&m68k.cycles, sizeof(m68k.cycles));
load_param(&m68k.cycles, sizeof(m68k.cycles));
load_param(&m68k.int_level, sizeof(m68k.int_level));
load_param(&m68k.stopped, sizeof(m68k.stopped));
}
......@@ -178,7 +178,7 @@ int state_load(unsigned char *state)
}
/* CD hardware */
bufferptr += scd_context_load(&state[bufferptr]);
bufferptr += scd_context_load(&state[bufferptr], version);
}
else if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
{
......
......@@ -2,7 +2,7 @@
* Genesis Plus
* Savestate support
*
* Copyright (C) 2007-2019 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2007-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......
......@@ -5,7 +5,7 @@
* Support for 16-bit & 8-bit hardware modes
*
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2007-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......@@ -132,8 +132,8 @@ void audio_set_rate(int samplerate, double framerate)
/* resampled to desired rate at the end of each frame, using Blip Buffer. */
blip_set_rates(snd.blips[0], mclk, samplerate);
/* Mega CD sound hardware */
if (system_hw == SYSTEM_MCD)
/* Mega CD sound hardware enabled ? */
if (snd.blips[1] && snd.blips[2])
{
/* number of SCD master clocks run per second */
mclk = (mclk / system_clock) * SCD_CLOCK;
......@@ -199,8 +199,8 @@ int audio_update(int16 *buffer)
/* run sound chips until end of frame */
int size = sound_update(mcycles_vdp);
/* Mega CD specific */
if (system_hw == SYSTEM_MCD)
/* Mega CD sound hardware enabled ? */
if (snd.blips[1] && snd.blips[2])
{
/* sync PCM chip with other sound chips */
pcm_update(size);
......
......@@ -5,7 +5,7 @@
* Support for 16-bit & 8-bit hardware modes
*
* Copyright (C) 1998-2003 Charles Mac Donald (original code)
* Copyright (C) 2007-2018 Eke-Eke (Genesis Plus GX)
* Copyright (C) 2007-2021 Eke-Eke (Genesis Plus GX)
*
* Redistribution and use of this code or any derivative works are permitted
* provided that the following conditions are met:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment