add IRegionable as an emulator service to indicate NTSC vs PAL, etc. Refactor cores that conveyed this information to use this service, fixed cheaty reflection to grab this info to use the service instead, marked some cores as region not applicable where it made sense to me (I'm sure I'm wrong in some cases)

This commit is contained in:
adelikat 2015-08-05 20:12:09 -04:00
parent 40f87f3391
commit ba21484ddd
22 changed files with 65 additions and 46 deletions

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using BizHawk.Common.ReflectionExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
using BizHawk.Emulation.Common.IEmulatorExtensions;
namespace BizHawk.Client.Common.MovieConversionExtensions
{
@ -283,10 +284,10 @@ namespace BizHawk.Client.Common.MovieConversionExtensions
movie.BoardName = Global.Emulator.BoardName;
}
if (Global.Emulator.HasPublicProperty("DisplayType"))
if (Global.Emulator.HasRegions())
{
var region = Global.Emulator.GetPropertyValue("DisplayType");
if ((DisplayType)region == DisplayType.PAL)
var region = Global.Emulator.AsRegionable().Region;
if (region == DisplayType.PAL)
{
movie.HeaderEntries.Add(HeaderKeys.PAL, "1");
}

View File

@ -84,6 +84,7 @@
<Compile Include="Interfaces\IInputPollable.cs" />
<Compile Include="Interfaces\IMemoryCallbackSystem.cs" />
<Compile Include="Interfaces\IMemoryDomains.cs" />
<Compile Include="Interfaces\IRegionable.cs" />
<Compile Include="Interfaces\ISaveRam.cs" />
<Compile Include="Interfaces\IEmulatorServiceProvider.cs" />
<Compile Include="Interfaces\ISettable.cs" />

View File

@ -200,6 +200,21 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
return true;
}
public static bool HasRegions(this IEmulator core)
{
if (core == null)
{
return false;
}
return core.ServiceProvider.HasService<IRegionable>();
}
public static IRegionable AsRegionable(this IEmulator core)
{
return (IRegionable)core.ServiceProvider.GetService<IRegionable>();
}
// TODO: a better place for these
public static bool IsImplemented(this MethodInfo info)
{

View File

@ -19,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Calculators
isPorted: false,
isReleased: true
)]
[ServiceNotApplicable(typeof(ISaveRam))]
[ServiceNotApplicable(typeof(ISaveRam), typeof(IRegionable))]
public partial class TI83 : IEmulator, IVideoProvider, IStatable, IDebuggable, IInputPollable, ISettable<TI83.TI83Settings, object>
{
[CoreConstructor("TI83")]

View File

@ -14,6 +14,7 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
isPorted: true,
isReleased: true
)]
[ServiceNotApplicable(typeof(ISaveRam), typeof(IRegionable))]
public partial class AppleII : IEmulator, IDriveLight
{
public AppleII(CoreComm comm, IEnumerable<GameInfo> gameInfoSet, IEnumerable<byte[]> romSet, Settings settings)

View File

@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
isPorted: false,
isReleased: false
)]
[ServiceNotApplicable(typeof(ISettable<,>))]
[ServiceNotApplicable(typeof(IRegionable), typeof(ISettable<,>))]
sealed public partial class C64 : IEmulator, IStatable, IInputPollable, IDriveLight, IDebuggable
{
// framework

View File

@ -320,11 +320,6 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
private bool _pal;
public DisplayType DisplayType
{
get { return _pal ? DisplayType.PAL : Common.DisplayType.NTSC; }
}
private void HardReset()
{
Ram = new byte[128];

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
isReleased: true
)]
[ServiceNotApplicable(typeof(ISaveRam), typeof(IDriveLight))]
public partial class Atari2600 : IEmulator, IStatable, IDebuggable, IInputPollable, ISettable<Atari2600.A2600Settings, Atari2600.A2600SyncSettings>
public partial class Atari2600 : IEmulator, IStatable, IDebuggable, IInputPollable, IRegionable, ISettable<Atari2600.A2600Settings, Atari2600.A2600SyncSettings>
{
private readonly GameInfo _game;
private int _frame;
@ -58,6 +58,11 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600
public IEmulatorServiceProvider ServiceProvider { get; private set; }
public DisplayType Region
{
get { return _pal ? DisplayType.PAL : Common.DisplayType.NTSC; }
}
public string SystemId { get { return "A26"; } }
public string BoardName { get { return _mapper.GetType().Name; } }

View File

@ -17,7 +17,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800
portedUrl: "http://emu7800.sourceforge.net/"
)]
[ServiceNotApplicable(typeof(ISettable<,>), typeof(IDriveLight))]
public partial class Atari7800 : IEmulator, ISaveRam, IDebuggable, IStatable, IInputPollable
public partial class Atari7800 : IEmulator, ISaveRam, IDebuggable, IStatable, IInputPollable, IRegionable
{
// TODO:
// some things don't work when you try to plug in a 2600 game
@ -164,7 +164,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800
}
private bool _pal;
public DisplayType DisplayType
public DisplayType Region
{
get { return _pal ? DisplayType.PAL : DisplayType.NTSC; }
}

View File

@ -12,7 +12,7 @@ using Newtonsoft.Json;
namespace BizHawk.Emulation.Cores.Atari.Lynx
{
[CoreAttributes("Handy", "K. Wilkins", true, true, "mednafen 0-9-34-1", "http://mednafen.sourceforge.net/")]
[ServiceNotApplicable(typeof(ISettable<,>), typeof(IDriveLight))]
[ServiceNotApplicable(typeof(ISettable<,>), typeof(IDriveLight), typeof(IRegionable))]
public partial class Lynx : IEmulator, IVideoProvider, ISyncSoundProvider, ISaveRam, IStatable, IInputPollable
{
IntPtr Core;

View File

@ -11,6 +11,7 @@ using System.ComponentModel;
namespace BizHawk.Emulation.Cores.Nintendo.GBA
{
[CoreAttributes("mGBA", "endrift", true, false, "NOT DONE", "NOT DONE", false)]
[ServiceNotApplicable(typeof(IDriveLight), typeof(IRegionable))]
public class MGBAHawk : IEmulator, IVideoProvider, ISyncSoundProvider, IGBAGPUViewable, ISaveRam, IStatable, IInputPollable, ISettable<object, MGBAHawk.SyncSettings>
{
IntPtr core;

View File

@ -15,7 +15,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
isReleased: false,
singleInstance: true
)]
[ServiceNotApplicable(typeof(IDriveLight))]
[ServiceNotApplicable(typeof(IDriveLight), typeof(IRegionable))]
public partial class GBA : IEmulator, IVideoProvider, ISyncSoundProvider, IGBAGPUViewable, ISaveRam, IStatable, IInputPollable
{
[CoreConstructor("GBA")]

View File

@ -14,7 +14,7 @@ using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Nintendo.GBA
{
[CoreAttributes("VBA-Next", "many authors", true, true, "cd508312a29ed8c29dacac1b11c2dce56c338a54", "https://github.com/libretro/vba-next")]
[ServiceNotApplicable(typeof(IDriveLight))]
[ServiceNotApplicable(typeof(IDriveLight), typeof(IRegionable))]
public partial class VBANext : IEmulator, IVideoProvider, ISyncSoundProvider, IInputPollable,
IGBAGPUViewable, ISaveRam, IStatable, IDebuggable, ISettable<object, VBANext.SyncSettings>
{

View File

@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
portedVersion: "SVN 344",
portedUrl: "http://gambatte.sourceforge.net/"
)]
[ServiceNotApplicable(typeof(IDriveLight))]
[ServiceNotApplicable(typeof(IDriveLight), typeof(IDriveLight))]
public partial class Gameboy : IEmulator, IVideoProvider, ISyncSoundProvider, ISaveRam, IStatable, IInputPollable,
IDebuggable, ISettable<Gameboy.GambatteSettings, Gameboy.GambatteSyncSettings>
{

View File

@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
singleInstance: true
)]
[ServiceNotApplicable(typeof(IDriveLight))]
public partial class N64 : IEmulator, ISaveRam, IDebuggable, IStatable, IInputPollable, IDisassemblable,
public partial class N64 : IEmulator, ISaveRam, IDebuggable, IStatable, IInputPollable, IDisassemblable, IRegionable,
ISettable<N64Settings, N64SyncSettings>
{
private readonly N64Input _inputProvider;
@ -104,7 +104,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
_display_type = DisplayType.NTSC;
break;
}
switch (DisplayType)
switch (Region)
{
case DisplayType.NTSC:
comm.VsyncNum = 60000;
@ -245,7 +245,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
public CoreComm CoreComm { get; private set; }
public DisplayType DisplayType { get { return _display_type; } }
public DisplayType Region { get { return _display_type; } }
public ISoundProvider SoundProvider { get { return null; } }

View File

@ -34,7 +34,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
}
CoreComm.ScreenLogicalOffsetX = videoProvider.left;
CoreComm.ScreenLogicalOffsetY = DisplayType == DisplayType.NTSC ? Settings.NTSC_TopLine : Settings.PAL_TopLine;
CoreComm.ScreenLogicalOffsetY = Region == DisplayType.NTSC ? Settings.NTSC_TopLine : Settings.PAL_TopLine;
SetPalette(Settings.Palette);

View File

@ -17,7 +17,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
isPorted: false,
isReleased: true
)]
public partial class NES : IEmulator, ISaveRam, IDebuggable, IStatable, IInputPollable,
public partial class NES : IEmulator, ISaveRam, IDebuggable, IStatable, IInputPollable, IRegionable,
ISettable<NES.NESSettings, NES.NESSyncSettings>
{
static readonly bool USE_DATABASE = true;
@ -182,7 +182,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public CoreComm CoreComm { get; private set; }
public DisplayType DisplayType { get { return _display_type; } }
public DisplayType Region { get { return _display_type; } }
class MyVideoProvider : IVideoProvider
{
@ -209,7 +209,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
{
int the_top;
int the_bottom;
if (emu.DisplayType == DisplayType.NTSC)
if (emu.Region == DisplayType.NTSC)
{
the_top = emu.Settings.NTSC_TopLine;
the_bottom = emu.Settings.NTSC_BottomLine;
@ -289,7 +289,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
{
get
{
if (emu.DisplayType == DisplayType.NTSC)
if (emu.Region == DisplayType.NTSC)
{
return emu.Settings.NTSC_BottomLine - emu.Settings.NTSC_TopLine + 1;
}

View File

@ -30,7 +30,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
portedUrl: "http://byuu.org/"
)]
[ServiceNotApplicable(typeof(IDriveLight))]
public unsafe class LibsnesCore : IEmulator, IVideoProvider, ISaveRam, IStatable, IInputPollable,
public unsafe class LibsnesCore : IEmulator, IVideoProvider, ISaveRam, IStatable, IInputPollable, IRegionable,
IDebuggable, ISettable<LibsnesCore.SnesSettings, LibsnesCore.SnesSyncSettings>
{
public LibsnesCore(GameInfo game, byte[] romData, bool deterministicEmulation, byte[] xmlData, CoreComm comm, object Settings, object SyncSettings)
@ -666,7 +666,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
api.QUERY_set_state_hook_write(!suppress && mcs.HasWrites);
}
public DisplayType DisplayType
public DisplayType Region
{
get
{

View File

@ -104,7 +104,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
value ^= 0x80;
}
if (Region == "Japan")
if (RegionStr == "Japan")
{
value ^= 0x40;
}

View File

@ -28,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
isReleased: true
)]
[ServiceNotApplicable(typeof(IDriveLight))]
public sealed partial class SMS : IEmulator, ISaveRam, IStatable, IInputPollable,
public sealed partial class SMS : IEmulator, ISaveRam, IStatable, IInputPollable, IRegionable,
IDebuggable, ISettable<SMS.SMSSettings, SMS.SMSSyncSettings>
{
// Constants
@ -92,7 +92,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
byte ForceStereoByte = 0xAD;
bool IsGame3D = false;
public DisplayType DisplayType { get; set; }
public DisplayType Region { get; set; }
public bool DeterministicEmulation { get { return true; } }
[CoreConstructor("SMS", "SG", "GG")]
@ -113,23 +113,23 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
Array.Resize(ref RomData, ((RomData.Length / BankSize) + 1) * BankSize);
RomBanks = (byte)(RomData.Length / BankSize);
DisplayType = DetermineDisplayType(SyncSettings.DisplayType, game.Region);
if (game["PAL"] && DisplayType != DisplayType.PAL)
Region = DetermineDisplayType(SyncSettings.DisplayType, game.Region);
if (game["PAL"] && Region != DisplayType.PAL)
{
DisplayType = DisplayType.PAL;
Region = DisplayType.PAL;
CoreComm.Notify("Display was forced to PAL mode for game compatibility.");
}
if (IsGameGear)
DisplayType = DisplayType.NTSC; // all game gears run at 60hz/NTSC mode
CoreComm.VsyncNum = DisplayType == DisplayType.NTSC ? 60 : 50;
Region = DisplayType.NTSC; // all game gears run at 60hz/NTSC mode
CoreComm.VsyncNum = Region == DisplayType.NTSC ? 60 : 50;
CoreComm.VsyncDen = 1;
Region = SyncSettings.ConsoleRegion;
if (Region == "Auto") Region = DetermineRegion(game.Region);
RegionStr = SyncSettings.ConsoleRegion;
if (RegionStr == "Auto") RegionStr = DetermineRegion(game.Region);
if (game["Japan"] && Region != "Japan")
if (game["Japan"] && RegionStr != "Japan")
{
Region = "Japan";
RegionStr = "Japan";
CoreComm.Notify("Region was forced to Japan for game compatibility.");
}
@ -145,7 +145,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
Cpu.WriteHardware = WritePort;
Cpu.MemoryCallbacks = MemoryCallbacks;
Vdp = new VDP(this, Cpu, IsGameGear ? VdpMode.GameGear : VdpMode.SMS, DisplayType);
Vdp = new VDP(this, Cpu, IsGameGear ? VdpMode.GameGear : VdpMode.SMS, Region);
(ServiceProvider as BasicServiceProvider).Register<IVideoProvider>(Vdp);
PSG = new SN76489();
YM2413 = new YM2413();
@ -198,7 +198,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
}
else if (game.System == "SMS")
{
BiosRom = comm.CoreFileProvider.GetFirmware("SMS", Region, false);
BiosRom = comm.CoreFileProvider.GetFirmware("SMS", RegionStr, false);
if (BiosRom != null && (game["RequireBios"] || SyncSettings.UseBIOS))
Port3E = 0xF7;
@ -428,7 +428,7 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem
public string BoardName { get { return null; } }
string region;
public string Region
public string RegionStr
{
get { return region; }
set

View File

@ -25,7 +25,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
portedUrl: "https://code.google.com/p/genplus-gx/",
singleInstance: true
)]
public class GPGX : IEmulator, ISyncSoundProvider, IVideoProvider, ISaveRam, IStatable,
public class GPGX : IEmulator, ISyncSoundProvider, IVideoProvider, ISaveRam, IStatable, IRegionable,
IInputPollable, IDebuggable, ISettable<GPGX.GPGXSettings, GPGX.GPGXSyncSettings>, IDriveLight
{
static GPGX AttachedCore = null;
@ -141,7 +141,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
LibGPGX.gpgx_get_fps(ref fpsnum, ref fpsden);
CoreComm.VsyncNum = fpsnum;
CoreComm.VsyncDen = fpsden;
DisplayType = CoreComm.VsyncRate > 55 ? DisplayType.NTSC : DisplayType.PAL;
Region = CoreComm.VsyncRate > 55 ? DisplayType.NTSC : DisplayType.PAL;
}
// compute state size
@ -749,7 +749,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
#region VideoProvider
public DisplayType DisplayType { get; private set; }
public DisplayType Region { get; private set; }
int[] vidbuff = new int[0];
int vwidth;

View File

@ -11,7 +11,7 @@ using System.Runtime.InteropServices;
namespace BizHawk.Emulation.Cores.WonderSwan
{
[CoreAttributes("Cygne/Mednafen", "Dox", true, true, "0.9.36.5", "http://mednafen.sourceforge.net/")]
[ServiceNotApplicable(typeof(IDriveLight))]
[ServiceNotApplicable(typeof(IDriveLight), typeof(IRegionable))]
public partial class WonderSwan : IEmulator, IVideoProvider, ISyncSoundProvider,
IInputPollable, IDebuggable
{