Skip to content

Commit

Permalink
Update Genesis Plus GX Core (#3889)
Browse files Browse the repository at this point in the history
* Added deep freeze functionality
* Adding support for selecting sound chip
* Adding LUA interface to the deepfreeze list
* Implemented sprite always on top in the VDP
* Found and fixed the issue that manifested itself in a reset Gargoyles and an outright fail in Ristar. The issue was the use of a union type containing overlapping cd and cartdrige data. Using struct now to keep them separated
* Fix PC reg in tracelogs
---------
Co-authored-by: feos <feykomylce@gmail.com>
Co-authored-by: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com>
  • Loading branch information
SergioMartin86 authored Apr 21, 2024
1 parent fd36a37 commit 5cb1fe0
Show file tree
Hide file tree
Showing 129 changed files with 976 additions and 86,703 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@
path = quicknes/core
url = https://github.com/TASEmulators/quickerNES.git
branch = main
[submodule "waterbox/gpgx/Genesis-Plus-GX"]
path = waterbox/gpgx/Genesis-Plus-GX
url = https://github.com/TASEmulators/Genesis-Plus-GX.git
branch = tasvideos-2
Binary file modified Assets/dll/gpgx.wbx.zst
Binary file not shown.
20 changes: 19 additions & 1 deletion src/BizHawk.Client.Common/lua/LuaHelperLibs/GenesisLuaLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;

using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.Sega.gpgx;

// ReSharper disable UnusedMember.Global
Expand All @@ -15,12 +16,15 @@ public GenesisLuaLibrary(ILuaLibraries luaLibsImpl, ApiContainer apiContainer, A

public override string Name => "genesis";

[RequiredService]
private GPGX gpgx { get; set; }

private GPGX.GPGXSettings Settings
{
get => APIs.Emulation.GetSettings() as GPGX.GPGXSettings ?? new GPGX.GPGXSettings();
set => APIs.Emulation.PutSettings(value);
}

[LuaMethodExample("if ( genesis.getlayer_bga( ) ) then\r\n\tconsole.log( \"Returns whether the bg layer A is displayed\" );\r\nend;")]
[LuaMethod("getlayer_bga", "Returns whether the bg layer A is displayed")]
public bool GetLayerBgA()
Expand Down Expand Up @@ -62,5 +66,19 @@ public void SetLayerBgW(bool value)
s.DrawBGW = value;
Settings = s;
}

[LuaMethodExample("genesis.add_deepfreeze_value( 0xFF00, 0x01 );")]
[LuaMethod("add_deepfreeze_value", "Adds an address to deepfreeze to a given value. The value will not change at any point during emulation.")]
public int AddDeepFreezeValue(int address, byte value)
{
return gpgx.AddDeepFreezeValue(address, value);
}

[LuaMethodExample("genesis.clear_deepfreeze_list();")]
[LuaMethod("clear_deepfreeze_list", "Clears the list of deep frozen variables")]
public void ClearDeepFreezeList()
{
gpgx.ClearDeepFreezeList();
}
}
}
12 changes: 12 additions & 0 deletions src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ISettable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ public class GPGXSyncSettings
[DefaultValue(LibGPGX.Region.Autodetect)]
public LibGPGX.Region Region { get; set; }

[DisplayName("FM Sound Chip Type")]
[Description("Sets the method used to emulate the FM synthesizer (main sound generator) of the Mega Drive/Genesis. 'MAME' options are fast, and run full speed on most systems. 'Nuked' options are cycle accurate, very high quality, and have substantial CPU requirements. The 'YM2612' chip is used by the original Model 1 Mega Drive/Genesis. The 'YM3438' is used in later Mega Drive/Genesis revisions.")]
[DefaultValue(LibGPGX.InitSettings.GenesisFMSoundChipType.MAME_YM2612)]
public LibGPGX.InitSettings.GenesisFMSoundChipType GenesisFMSoundChip { get; set; }

[DisplayName("Audio Filter")]
[DefaultValue(LibGPGX.InitSettings.FilterType.LowPass)]
public LibGPGX.InitSettings.FilterType Filter { get; set; }
Expand Down Expand Up @@ -303,6 +308,11 @@ public class GPGXSyncSettings
[DefaultValue(0xffff00ff)]
public uint BackdropColor { get; set; }

[DisplayName("Sprites always on top")]
[Description("Forces sprites to always be displayed on top")]
[DefaultValue(false)]
public bool SpritesAlwaysOnTop { get; set; }

public LibGPGX.InitSettings GetNativeSettings(GameInfo game)
{
return new LibGPGX.InitSettings
Expand All @@ -320,6 +330,8 @@ public LibGPGX.InitSettings GetNativeSettings(GameInfo game)
InputSystemB = SystemForSystem(ControlTypeRight),
Region = Region,
ForceSram = game["sram"],
GenesisFMSoundChip = GenesisFMSoundChip,
SpritesAlwaysOnTop = SpritesAlwaysOnTop
};
}

Expand Down
21 changes: 18 additions & 3 deletions src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{
[PortedCore(CoreNames.Gpgx, "", "r874", "https://code.google.com/p/genplus-gx/")]
[PortedCore(CoreNames.Gpgx, "Eke-Eke", "25a90c6", "https://github.com/ekeeke/Genesis-Plus-GX")]
public partial class GPGX : IEmulator, IVideoProvider, ISaveRam, IStatable, IRegionable,
IInputPollable, IDebuggable, IDriveLight, ICodeDataLogger, IDisassemblable
{
Expand Down Expand Up @@ -44,7 +44,7 @@ public GPGX(CoreLoadParameters<GPGXSettings, GPGXSyncSettings> lp)
SbrkHeapSizeKB = 512,
SealedHeapSizeKB = 4 * 1024,
InvisibleHeapSizeKB = 4 * 1024,
PlainHeapSizeKB = 34 * 1024,
PlainHeapSizeKB = 48 * 1024,
MmapHeapSizeKB = 1 * 1024,
SkipCoreConsistencyCheck = lp.Comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxCoreConsistencyCheck),
SkipMemoryConsistencyCheck = lp.Comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck),
Expand Down Expand Up @@ -214,7 +214,7 @@ private int load_archive(string filename, IntPtr buffer, int maxsize)
srcdata = GetCDData(_cds[0]);
if (srcdata.Length != maxsize)
{
Console.WriteLine("Couldn't satisfy firmware request {0} because of struct size.", filename);
Console.WriteLine("Couldn't satisfy firmware request {0} because of struct size ({1} != {2}).", filename, srcdata.Length, maxsize);
return 0;
}
}
Expand Down Expand Up @@ -314,8 +314,12 @@ public static LibGPGX.CDData GetCDDataStruct(Disc cd)
//zero 07-jul-2015 - throws a dollar in the pile, since he probably messed it up worse
for (int i = 0; i < LibGPGX.CD_MAX_TRACKS; i++)
{
ret.tracks[i].loopEnabled = 0;
ret.tracks[i].loopOffset = 0;

if (i < ntrack)
{
ret.tracks[i].mode = ses.Tracks[i].Mode;
ret.tracks[i].start = ses.Tracks[i + 1].LBA;
ret.tracks[i].end = ses.Tracks[i + 2].LBA;
if (i == ntrack - 1)
Expand All @@ -326,6 +330,7 @@ public static LibGPGX.CDData GetCDDataStruct(Disc cd)
}
else
{
ret.tracks[i].mode = 0;
ret.tracks[i].start = 0;
ret.tracks[i].end = 0;
}
Expand Down Expand Up @@ -412,6 +417,16 @@ public VDPView UpdateVDPViewContext()
Core.gpgx_flush_vram(); // fully regenerate internal caches as needed
return new VDPView(v, _elf);
}

public int AddDeepFreezeValue(int address, byte value)
{
return Core.gpgx_add_deepfreeze_list_entry(address, value);
}

public void ClearDeepFreezeList()
{
Core.gpgx_clear_deepfreeze_list();
}

public DisplayType Region { get; }
}
Expand Down
22 changes: 22 additions & 0 deletions src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/LibGPGX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,23 @@ public enum FilterType : byte
ThreeBand = 2
}
public FilterType Filter;

public INPUT_SYSTEM InputSystemA;
public INPUT_SYSTEM InputSystemB;
public bool SixButton;
public bool ForceSram;

public enum GenesisFMSoundChipType : byte
{
MAME_YM2612,
MAME_ASIC_YM3438,
MAME_Enhanced_YM3438,
Nuked_YM2612,
Nuked_YM3438
}
public GenesisFMSoundChipType GenesisFMSoundChip;

public bool SpritesAlwaysOnTop;
}

[BizImport(CallingConvention.Cdecl)]
Expand Down Expand Up @@ -271,6 +284,9 @@ public struct CDTrack
{
public int start;
public int end;
public int mode;
public int loopEnabled;
public int loopOffset;
}

[StructLayout(LayoutKind.Sequential)]
Expand All @@ -282,6 +298,12 @@ public class CDData
public readonly CDTrack[] tracks = new CDTrack[CD_MAX_TRACKS];
}

[BizImport(CallingConvention.Cdecl)]
public abstract int gpgx_add_deepfreeze_list_entry(int address, byte value);

[BizImport(CallingConvention.Cdecl)]
public abstract void gpgx_clear_deepfreeze_list();

[BizImport(CallingConvention.Cdecl)]
public abstract void gpgx_set_cdd_callback(cd_read_cb cddcb);

Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Emulation.Cores/CoreNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class CoreNames
public const string GBHawkLink3x = "GBHawkLink3x";
public const string GBHawkLink4x = "GBHawkLink4x";
public const string GGHawkLink = "GGHawkLink";
public const string Gpgx = "Genplus-gx";
public const string Gpgx = "GenesisPlusGX";
public const string Handy = "Handy";
public const string HyperNyma = "HyperNyma";
public const string IntelliHawk = "IntelliHawk";
Expand Down
9 changes: 0 additions & 9 deletions waterbox/gpgx/.vscode/settings.json

This file was deleted.

1 change: 1 addition & 0 deletions waterbox/gpgx/Genesis-Plus-GX
Submodule Genesis-Plus-GX added at 499dd3
84 changes: 79 additions & 5 deletions waterbox/gpgx/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,87 @@
CCFLAGS := -Icore -Iutil -Icore/m68k -Icore/z80 -Icore/input_hw \
-Icore/cart_hw -Icore/cart_hw/svp -Icore/sound -Icore/ntsc -Icore/cd_hw \
GPGX_DIR := Genesis-Plus-GX

CCFLAGS := -Iutil \
-I${GPGX_DIR}/core \
-I${GPGX_DIR}/core/m68k \
-I${GPGX_DIR}/core/z80 \
-I${GPGX_DIR}/core/input_hw \
-I${GPGX_DIR}/core/cart_hw \
-I${GPGX_DIR}/core/cart_hw/svp \
-I${GPGX_DIR}/core/sound \
-I${GPGX_DIR}/core/ntsc \
-I${GPGX_DIR}/core/cd_hw \
-I${GPGX_DIR}/core/debug \
-Icinterface \
-Iutil \
-Wall -Werror=pointer-to-int-cast -Werror=int-to-pointer-cast -Werror=implicit-function-declaration \
-std=c99 -fomit-frame-pointer \
-DLSB_FIRST -DUSE_32BPP_RENDERING -DINLINE=static\ __inline__ -fcommon
-std=c99 -fomit-frame-pointer -Wfatal-errors \
-DUSE_BIZHAWK_CALLBACKS \
-DHAVE_YM3438_CORE \
-DHAVE_OPLL_CORE \
-DUSE_RAM_DEEPFREEZE \
-DLSB_FIRST \
-DUSE_32BPP_RENDERING \
-DHOOK_CPU \
-DINLINE=static\ __inline__ \
-fcommon

LDFLAGS :=

TARGET := gpgx.wbx

SRCS = $(shell find $(ROOT_DIR) -type f -name '*.c')
SRCS = $(GPGX_DIR)/core/sound/sound.c \
$(GPGX_DIR)/core/sound/ym3438.c \
$(GPGX_DIR)/core/sound/opll.c \
$(GPGX_DIR)/core/sound/eq.c \
$(GPGX_DIR)/core/sound/ym2413.c \
$(GPGX_DIR)/core/sound/blip_buf.c \
$(GPGX_DIR)/core/sound/psg.c \
$(GPGX_DIR)/core/sound/ym2612.c \
$(GPGX_DIR)/core/membnk.c \
$(GPGX_DIR)/core/vdp_ctrl.c \
$(GPGX_DIR)/core/z80/z80.c \
$(GPGX_DIR)/core/io_ctrl.c \
$(GPGX_DIR)/core/ntsc/sms_ntsc.c \
$(GPGX_DIR)/core/ntsc/md_ntsc.c \
$(GPGX_DIR)/core/m68k/s68kcpu.c \
$(GPGX_DIR)/core/m68k/m68kcpu.c \
$(GPGX_DIR)/core/memz80.c \
$(GPGX_DIR)/core/genesis.c \
$(GPGX_DIR)/core/vdp_render.c \
$(GPGX_DIR)/core/system.c \
$(GPGX_DIR)/core/cd_hw/cd_cart.c \
$(GPGX_DIR)/core/cd_hw/cdc.c \
$(GPGX_DIR)/core/cd_hw/pcm.c \
$(GPGX_DIR)/core/cd_hw/gfx.c \
$(GPGX_DIR)/core/cd_hw/scd.c \
$(GPGX_DIR)/core/cd_hw/cdd.c \
$(GPGX_DIR)/core/input_hw/sportspad.c \
$(GPGX_DIR)/core/input_hw/activator.c \
$(GPGX_DIR)/core/input_hw/mouse.c \
$(GPGX_DIR)/core/input_hw/paddle.c \
$(GPGX_DIR)/core/input_hw/gamepad.c \
$(GPGX_DIR)/core/input_hw/input.c \
$(GPGX_DIR)/core/input_hw/terebi_oekaki.c \
$(GPGX_DIR)/core/input_hw/teamplayer.c \
$(GPGX_DIR)/core/input_hw/graphic_board.c \
$(GPGX_DIR)/core/input_hw/lightgun.c \
$(GPGX_DIR)/core/input_hw/xe_1ap.c \
$(GPGX_DIR)/core/mem68k.c \
$(GPGX_DIR)/core/cart_hw/svp/ssp16.c \
$(GPGX_DIR)/core/cart_hw/svp/svp.c \
$(GPGX_DIR)/core/cart_hw/areplay.c \
$(GPGX_DIR)/core/cart_hw/eeprom_spi.c \
$(GPGX_DIR)/core/cart_hw/sram.c \
$(GPGX_DIR)/core/cart_hw/eeprom_93c.c \
$(GPGX_DIR)/core/cart_hw/sms_cart.c \
$(GPGX_DIR)/core/cart_hw/eeprom_i2c.c \
$(GPGX_DIR)/core/cart_hw/ggenie.c \
$(GPGX_DIR)/core/cart_hw/md_cart.c \
$(GPGX_DIR)/core/cart_hw/megasd.c \
$(GPGX_DIR)/core/debug/cpuhook.c \
$(GPGX_DIR)/core/loadrom.c \
cinterface/cddImpl.c \
cinterface/cinterface.c \
util/scrc32.c

include ../common.mak
3 changes: 1 addition & 2 deletions waterbox/gpgx/cinterface/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ typedef ECL_ENTRY void (*CDCallback)(int32 addr, int32 addrtype, int32 flags);
extern ECL_ENTRY void (*biz_execcb)(unsigned addr);
extern ECL_ENTRY void (*biz_readcb)(unsigned addr);
extern ECL_ENTRY void (*biz_writecb)(unsigned addr);
extern CDCallback biz_cdcallback;
extern unsigned biz_lastpc;
extern CDCallback biz_cdcb;

extern ECL_ENTRY void (*cdd_readcallback)(int lba, void *dest, int audio);

Expand Down
Loading

0 comments on commit 5cb1fe0

Please sign in to comment.