Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Assets/defctrl.json
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,20 @@
"P1 Z": "D, J1 B6, X1 RightShoulder",
"P1 Mode": "E, J1 B9, X1 Back"
},
"BlastEM Genesis Controller": {
"P1 Up": "Up, J1 POV1U, X1 DpadUp, X1 LStickUp",
"P1 Down": "Down, J1 POV1D, X1 DpadDown, X1 LStickDown",
"P1 Left": "Left, J1 POV1L, X1 DpadLeft, X1 LStickLeft",
"P1 Right": "Right, J1 POV1R, X1 DpadRight, X1 LStickRight",
"P1 A": "Z, J1 B1, X1 X",
"P1 B": "X, J1 B2, X1 A",
"P1 C": "C, J1 B4, X1 Y",
"P1 Start": "Enter, J1 B10, X1 Start",
"P1 X": "A, J1 B3, X1 B",
"P1 Y": "S, J1 B5, X1 LeftShoulder",
"P1 Z": "D, J1 B6, X1 RightShoulder",
"P1 Mode": "E, J1 B9, X1 Back"
},
"WonderSwan Controller": {
"P1 X1": "Up, J1 POV1U, X1 DpadUp, X1 LStickUp",
"P1 X3": "Down, J1 POV1D, X1 DpadDown, X1 LStickDown",
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Client.Common/config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class Config
[ CoreNames.GambatteLink, CoreNames.GBHawkLink, CoreNames.GBHawkLink3x, CoreNames.GBHawkLink4x ]),
([ VSystemID.Raw.SGB ],
[ CoreNames.Gambatte, CoreNames.Bsnes115, CoreNames.SubBsnes115, CoreNames.Bsnes ]),
([ VSystemID.Raw.GEN ],
[ CoreNames.Gpgx, CoreNames.PicoDrive, CoreNames.BlastEm ]),
([ VSystemID.Raw.N64 ],
[ CoreNames.Mupen64Plus, CoreNames.Ares64 ]),
([ VSystemID.Raw.NES ],
Expand Down
140 changes: 140 additions & 0 deletions src/BizHawk.Emulation.Cores/Consoles/Sega/BlastEM/BlastEM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using System.ComponentModel;

using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Waterbox;
using BizHawk.Emulation.DiscSystem;

namespace BizHawk.Emulation.Cores.Consoles.Sega.BlastEm
{
[PortedCore(CoreNames.BlastEm, "mikepavone", "1234567", "https://www.retrodev.com/repos/blastem/file/tip")]
public class BlastEm : WaterboxCore, IRegionable, ISettable<object, BlastEm.SyncSettings>
{
private readonly LibBlastEm _core;
private readonly bool _isPal = false;

[CoreConstructor(VSystemID.Raw.GEN, Priority = CorePriority.Low)]
public BlastEm(CoreComm comm, GameInfo game, byte[] rom, bool deterministic, SyncSettings syncSettings)
: this(comm, game, rom, null, deterministic, syncSettings)
{ }

private BlastEm(CoreComm comm, GameInfo game, byte[] rom, Disc cd, bool deterministic, SyncSettings syncSettings)
: base(comm, new Configuration
{
MaxSamples = 2048,
DefaultWidth = 320,
DefaultHeight = 224,
MaxWidth = 320,
MaxHeight = 480,
SystemId = VSystemID.Raw.GEN,
})
{
_syncSettings = syncSettings ?? new SyncSettings();

_core = PreInit<LibBlastEm>(new WaterboxOptions
{
Filename = "libblastem.wbx",
SbrkHeapSizeKB = 3 * 512,
SealedHeapSizeKB = 10 * 1024,
MmapHeapSizeKB = 4 * 1024,
PlainHeapSizeKB = 8 * 1024,
InvisibleHeapSizeKB = 32 * 1024,
SkipCoreConsistencyCheck = comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxCoreConsistencyCheck),
SkipMemoryConsistencyCheck = comm.CorePreferences.HasFlag(CoreComm.CorePreferencesFlags.WaterboxMemoryConsistencyCheck),
}, Array.Empty<Delegate>());

if (cd == null)
{
_exe.AddReadonlyFile(rom, "romfile.md");
}

if (!_core.Init(cd != null, false, LibBlastEm.Region.Auto, _syncSettings.RegionOverride))
throw new InvalidOperationException("Core rejected the file!");

PostInit();
ControllerDefinition = SegaController;
DeterministicEmulation = deterministic;

_isPal = false;
VsyncNumerator = _isPal ? 53203424 : 53693175;
VsyncDenominator = _isPal ? 3420 * 313 : 3420 * 262;
}

public static readonly ControllerDefinition SegaController = new ControllerDefinition("BlastEM Genesis Controller")
{
BoolButtons =
{
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 A", "P1 B", "P1 C", "P1 Start", "P1 X", "P1 Y", "P1 Z", "P1 Mode",
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 A", "P2 B", "P2 C", "P2 Start", "P2 X", "P2 Y", "P2 Z", "P2 Mode",
"Power", "Reset",
},
}.MakeImmutable();

private static readonly string[] ButtonOrders =
{
"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 B", "P1 C", "P1 A", "P1 Start", "P1 Z", "P1 Y", "P1 X", "P1 Mode",
"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 B", "P2 C", "P2 A", "P2 Start", "P2 Z", "P2 Y", "P2 X", "P2 Mode",
"Power", "Reset",
};

[CoreSettings]
public class SyncSettings
{
[DefaultValue(LibBlastEm.Region.Auto)]
public LibBlastEm.Region RegionOverride { get; set; }

public SyncSettings Clone()
{
return (SyncSettings)MemberwiseClone();
}

public static bool NeedsReboot(SyncSettings x, SyncSettings y)
{
return !DeepEquality.DeepEquals(x, y);
}

public SyncSettings()
{
SettingsUtil.SetDefaultValues(this);
}
}

private SyncSettings _syncSettings;

public object GetSettings()
{
return new object();
}

public SyncSettings GetSyncSettings()
{
return _syncSettings.Clone();
}

public PutSettingsDirtyBits PutSettings(object o)
{
return PutSettingsDirtyBits.None;
}

public PutSettingsDirtyBits PutSyncSettings(SyncSettings o)
{
var ret = SyncSettings.NeedsReboot(_syncSettings, o);
_syncSettings = o;
return ret ? PutSettingsDirtyBits.RebootCore : PutSettingsDirtyBits.None;
}

public DisplayType Region => _isPal ? DisplayType.PAL : DisplayType.NTSC;
protected override LibWaterboxCore.FrameInfo FrameAdvancePrep(IController controller, bool render, bool rendersound)
{
var b = 0;
var v = 1;
foreach (var s in ButtonOrders)
{
if (controller.IsPressed(s))
b |= v;
v <<= 1;
}
return new LibBlastEm.FrameInfo { Buttons = b };
}
}
}
28 changes: 28 additions & 0 deletions src/BizHawk.Emulation.Cores/Consoles/Sega/BlastEM/LibBlastEM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Runtime.InteropServices;

using BizHawk.BizInvoke;
using BizHawk.Emulation.Cores.Waterbox;

namespace BizHawk.Emulation.Cores.Consoles.Sega.BlastEm
{
public abstract class LibBlastEm : LibWaterboxCore
{
public enum Region : int
{
Auto = 0,
JapanNTSC = 1,
JapanPAL = 2,
US = 4,
Europe = 8,
}

[BizImport(CC)]
public abstract bool Init(bool cd, bool _32xPreinit, Region regionAutoOrder, Region regionOverride);

[StructLayout(LayoutKind.Sequential)]
public new class FrameInfo : LibWaterboxCore.FrameInfo
{
public int Buttons;
}
}
}
1 change: 1 addition & 0 deletions src/BizHawk.Emulation.Cores/CoreNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ public static class CoreNames
public const string VirtualBoyee = "Virtual Boyee";
public const string VirtualJaguar = "Virtual Jaguar";
public const string ZXHawk = "ZXHawk";
public const string BlastEm = "BlastEm";
}
}
Loading