From 62a13d961d667a99ef6e426ade0f4af5c96d9d46 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 5 May 2017 11:21:37 -0500 Subject: [PATCH] Move VsyncNum and VsyncDen out of CoreComm and into IVideoProvider --- .../BitmapBufferVideoProvider.cs | 10 ++++++ BizHawk.Client.Common/QuickBmpFile.cs | 10 ++++++ BizHawk.Client.EmuHawk/AVOut/AviWriter.cs | 5 ++- .../AVOut/BmpVideoProvder.cs | 10 ++++++ .../DisplayManager/DisplayManager.cs | 10 ++++++ BizHawk.Client.EmuHawk/MainForm.cs | 4 +-- BizHawk.Client.EmuHawk/Sound/Sound.cs | 5 +-- .../Sound/Utilities/SoundOutputProvider.cs | 3 +- .../DisplayManager/DisplayManager.cs | 10 ++++++ BizHawk.Client.MultiHawk/Mainform.cs | 2 +- .../Base Implementations/NullEmulator.cs | 4 +++ .../Base Implementations/NullVideo.cs | 6 ++++ BizHawk.Emulation.Common/CoreComms.cs | 5 --- BizHawk.Emulation.Common/Extensions.cs | 31 +++++++++++++++++-- .../Interfaces/Services/IVideoProvider.cs | 10 ++++++ .../Calculator/TI83.IVideoProvider.cs | 2 ++ .../AppleII/AppleII.IVideoProvider.cs | 18 +++++++++++ .../Computers/Commodore64/C64.cs | 4 --- .../Commodore64/MOS/Vic.VideoProvider.cs | 6 ++++ .../Consoles/Atari/2600/Atari2600.Core.cs | 8 +---- .../Consoles/Atari/2600/Tia/TIA.cs | 20 +++++++++--- .../Consoles/Atari/7800/Atari7800.cs | 10 +++--- .../Atari/lynx/Lynx.IVideoProvider.cs | 4 +++ .../Consoles/Atari/lynx/Lynx.cs | 3 -- .../Consoles/Coleco/TMS9918A.cs | 18 +++++++++++ .../Consoles/Intellivision/STIC.cs | 18 +++++++++++ .../Nintendo/GBA/MGBAHawk.IVideoProvider.cs | 5 +++ .../Consoles/Nintendo/GBA/MGBAHawk.cs | 3 -- .../Nintendo/GBA/VBANext.IVideoProvider.cs | 4 +++ .../Consoles/Nintendo/GBA/VBANext.cs | 2 -- .../Gameboy/Gambatte.IVideoProvider.cs | 4 +++ .../Consoles/Nintendo/Gameboy/Gambatte.cs | 2 -- .../Gameboy/GambatteLink.IVideoProvider.cs | 4 +++ .../Consoles/Nintendo/Gameboy/GambatteLink.cs | 2 -- .../Consoles/Nintendo/N64/N64.cs | 23 +++++++------- .../Consoles/Nintendo/N64/N64VideoProvider.cs | 2 ++ .../Consoles/Nintendo/NES/NES.Core.cs | 16 +++++----- .../Consoles/Nintendo/NES/NES.cs | 2 ++ .../QuickNES/QuickNES.IVideoProvider.cs | 3 ++ .../Consoles/Nintendo/QuickNES/QuickNES.cs | 2 -- .../SNES/LibsnesCore.IVideoProvider.cs | 3 ++ .../Consoles/Nintendo/SNES/LibsnesCore.cs | 8 ++--- .../Consoles/Nintendo/SNES9X/Snes9x.cs | 18 +++++++++++ .../Consoles/PC Engine/VDC.Render.cs | 19 ++++++++++++ .../Consoles/PC Engine/VPC.cs | 18 +++++++++++ .../Consoles/Sega/SMS/SMS.cs | 3 -- .../Consoles/Sega/SMS/VDP.cs | 4 +++ .../Consoles/Sega/Saturn/Yabause.cs | 18 +++++++++++ .../Consoles/Sega/gpgx/GPGX.IVideoProvider.cs | 4 +++ .../Consoles/Sega/gpgx/GPGX.cs | 6 ++-- .../Sega/gpgx64/GPGX.IVideoProvider.cs | 4 +++ .../Consoles/Sega/gpgx64/GPGX.cs | 6 ++-- .../Consoles/Sony/PSP/PSP.cs | 20 ++++++++++-- .../Consoles/Sony/PSX/Octoshock.cs | 11 ++++--- .../Consoles/WonderSwan/WonderSwan.cs | 6 ++-- .../Libretro/LibretroCore.cs | 7 +++-- Settings.StyleCop | 1 + 57 files changed, 375 insertions(+), 91 deletions(-) diff --git a/BizHawk.Client.Common/BitmapBufferVideoProvider.cs b/BizHawk.Client.Common/BitmapBufferVideoProvider.cs index b5fd7f6abc..9e95a036a1 100644 --- a/BizHawk.Client.Common/BitmapBufferVideoProvider.cs +++ b/BizHawk.Client.Common/BitmapBufferVideoProvider.cs @@ -52,5 +52,15 @@ namespace BizHawk.Client.Common { get { return 0; } } + + public int VsyncNum + { + get { throw new InvalidOperationException(); } + } + + public int VsyncDen + { + get { throw new InvalidOperationException(); } + } } } diff --git a/BizHawk.Client.Common/QuickBmpFile.cs b/BizHawk.Client.Common/QuickBmpFile.cs index f3b0c2d4fd..9b81e8db96 100644 --- a/BizHawk.Client.Common/QuickBmpFile.cs +++ b/BizHawk.Client.Common/QuickBmpFile.cs @@ -221,6 +221,16 @@ namespace BizHawk.Client.Common public int BufferWidth { get; set; } public int BufferHeight { get; set; } public int BackgroundColor => unchecked((int)0xff000000); + + public int VsyncNum + { + get { throw new InvalidOperationException(); } + } + + public int VsyncDen + { + get { throw new InvalidOperationException(); } + } } public static unsafe bool Load(IVideoProvider v, Stream s) diff --git a/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs b/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs index 9f856bb922..c66fd39da2 100644 --- a/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs +++ b/BizHawk.Client.EmuHawk/AVOut/AviWriter.cs @@ -112,6 +112,8 @@ namespace BizHawk.Client.EmuHawk public int BufferWidth { get; } public int BufferHeight { get; } public int BackgroundColor { get; } + public int VsyncNum { get; } + public int VsyncDen { get; } public VideoCopy(IVideoProvider c) { _vb = (int[])c.GetVideoBuffer().Clone(); @@ -120,6 +122,8 @@ namespace BizHawk.Client.EmuHawk BackgroundColor = c.BackgroundColor; VirtualWidth = c.VirtualWidth; VirtualHeight = c.VirtualHeight; + VsyncNum = c.VsyncNum; + VsyncDen = c.VsyncDen; } public int[] GetVideoBuffer() @@ -128,7 +132,6 @@ namespace BizHawk.Client.EmuHawk } } - /// /// opens an avi file for recording with the supplied enumerator used to name files. /// set a video codec token first. diff --git a/BizHawk.Client.EmuHawk/AVOut/BmpVideoProvder.cs b/BizHawk.Client.EmuHawk/AVOut/BmpVideoProvder.cs index e93250a3e5..16f73f0517 100644 --- a/BizHawk.Client.EmuHawk/AVOut/BmpVideoProvder.cs +++ b/BizHawk.Client.EmuHawk/AVOut/BmpVideoProvder.cs @@ -49,5 +49,15 @@ namespace BizHawk.Client.EmuHawk public int BufferHeight => _bmp.Height; public int BackgroundColor => 0; + + public int VsyncNum + { + get { throw new InvalidOperationException(); } + } + + public int VsyncDen + { + get { throw new InvalidOperationException(); } + } } } diff --git a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index c2820aa138..6d853022b3 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -416,6 +416,16 @@ namespace BizHawk.Client.EmuHawk public int BufferWidth { get; set; } public int BufferHeight { get; set; } public int BackgroundColor { get; set; } + + public int VsyncNum + { + get { throw new InvalidOperationException(); } + } + + public int VsyncDen + { + get { throw new InvalidOperationException(); } + } } void FixRatio(float x, float y, int inw, int inh, out int outw, out int outh) diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 6d26cc5d2e..28d5c4ea4e 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -1861,7 +1861,7 @@ namespace BizHawk.Client.EmuHawk Global.DisableSecondaryThrottling = _unthrottled || turbo || fastForward || rewind; // realtime throttle is never going to be so exact that using a double here is wrong - _throttle.SetCoreFps(Emulator.CoreComm.VsyncRate); + _throttle.SetCoreFps(Emulator.VsyncRate()); _throttle.signal_paused = EmulatorPaused; _throttle.signal_unthrottle = _unthrottled || turbo; //zero 26-mar-2016 - vsync and vsync throttle here both is odd, but see comments elsewhere about triple buffering @@ -3034,7 +3034,7 @@ namespace BizHawk.Client.EmuHawk aw = new AudioStretcher(aw); } - aw.SetMovieParameters(Emulator.CoreComm.VsyncNum, Emulator.CoreComm.VsyncDen); + aw.SetMovieParameters(Emulator.VsyncNum(), Emulator.VsyncDen()); if (_avwriterResizew > 0 && _avwriterResizeh > 0) { aw.SetVideoParameters(_avwriterResizew, _avwriterResizeh); diff --git a/BizHawk.Client.EmuHawk/Sound/Sound.cs b/BizHawk.Client.EmuHawk/Sound/Sound.cs index 31174fb69b..84362490e7 100644 --- a/BizHawk.Client.EmuHawk/Sound/Sound.cs +++ b/BizHawk.Client.EmuHawk/Sound/Sound.cs @@ -2,6 +2,7 @@ using System.Threading; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk @@ -99,7 +100,7 @@ namespace BizHawk.Client.EmuHawk } else if (source.SyncMode == SyncSoundMode.Async) { - _bufferedAsync.RecalculateMagic(Global.Emulator.CoreComm.VsyncRate); + _bufferedAsync.RecalculateMagic(Global.Emulator.VsyncRate()); _bufferedProvider = _bufferedAsync; } else throw new InvalidOperationException("Unsupported sync mode."); @@ -112,7 +113,7 @@ namespace BizHawk.Client.EmuHawk internal void HandleInitializationOrUnderrun(bool isUnderrun, ref int samplesNeeded) { // Fill device buffer with silence but leave enough room for one frame - int samplesPerFrame = (int)Math.Round(SampleRate / Global.Emulator.CoreComm.VsyncRate); + int samplesPerFrame = (int)Math.Round(SampleRate / (double)Global.Emulator.VsyncRate()); int silenceSamples = Math.Max(samplesNeeded - samplesPerFrame, 0); _outputDevice.WriteSamples(new short[silenceSamples * 2], silenceSamples); samplesNeeded -= silenceSamples; diff --git a/BizHawk.Client.EmuHawk/Sound/Utilities/SoundOutputProvider.cs b/BizHawk.Client.EmuHawk/Sound/Utilities/SoundOutputProvider.cs index 76995020e0..1caa777d46 100644 --- a/BizHawk.Client.EmuHawk/Sound/Utilities/SoundOutputProvider.cs +++ b/BizHawk.Client.EmuHawk/Sound/Utilities/SoundOutputProvider.cs @@ -4,6 +4,7 @@ using System.Linq; using BizHawk.Client.Common; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common.IEmulatorExtensions; namespace BizHawk.Client.EmuHawk { @@ -120,7 +121,7 @@ namespace BizHawk.Client.EmuHawk private double AdvertisedSamplesPerFrame { - get { return SampleRate / Global.Emulator.CoreComm.VsyncRate; } + get { return SampleRate / Global.Emulator.VsyncRate(); } } public void GetSamples(short[] samples) diff --git a/BizHawk.Client.MultiHawk/DisplayManager/DisplayManager.cs b/BizHawk.Client.MultiHawk/DisplayManager/DisplayManager.cs index ce304a8d0d..14e59ba360 100644 --- a/BizHawk.Client.MultiHawk/DisplayManager/DisplayManager.cs +++ b/BizHawk.Client.MultiHawk/DisplayManager/DisplayManager.cs @@ -282,6 +282,16 @@ namespace BizHawk.Client.MultiHawk public int BufferWidth { get; set; } public int BufferHeight { get; set; } public int BackgroundColor { get; set; } + + public int VsyncNum + { + get { throw new InvalidOperationException(); } + } + + public int VsyncDen + { + get { throw new InvalidOperationException(); } + } } void FixRatio(float x, float y, int inw, int inh, out int outw, out int outh) diff --git a/BizHawk.Client.MultiHawk/Mainform.cs b/BizHawk.Client.MultiHawk/Mainform.cs index 4cd8b9f621..7ff20054db 100644 --- a/BizHawk.Client.MultiHawk/Mainform.cs +++ b/BizHawk.Client.MultiHawk/Mainform.cs @@ -956,7 +956,7 @@ namespace BizHawk.Client.MultiHawk Global.DisableSecondaryThrottling = /*_unthrottled || TODO */ turbo || fastForward; // realtime throttle is never going to be so exact that using a double here is wrong - _throttle.SetCoreFps(EmulatorWindows.Master.Emulator.CoreComm.VsyncRate); + _throttle.SetCoreFps(EmulatorWindows.Master.Emulator.VsyncRate()); _throttle.signal_paused = EmulatorPaused; _throttle.signal_unthrottle = /*_unthrottled || TODO */ turbo; _throttle.signal_overrideSecondaryThrottle = fastForward && (Global.Config.SoundThrottle || Global.Config.VSyncThrottle || Global.Config.VSync); diff --git a/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs b/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs index a6f22f5be4..dc8a50e9c1 100644 --- a/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs +++ b/BizHawk.Emulation.Common/Base Implementations/NullEmulator.cs @@ -110,6 +110,10 @@ namespace BizHawk.Emulation.Common public int BackgroundColor => NullVideo.DefaultBackgroundColor; + public int VsyncNum => NullVideo.DefaultVsyncNum; + + public int VsyncDen => NullVideo.DefaultVsyncDen; + #endregion #region ISoundProvider diff --git a/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs b/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs index e607547a44..65e04f1ce6 100644 --- a/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs +++ b/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs @@ -17,6 +17,8 @@ public static int DefaultWidth { get; } = 256; public static int DefaultHeight { get; } = 192; public static int DefaultBackgroundColor { get; } = 0; + public static int DefaultVsyncNum { get; } = 60; + public static int DefaultVsyncDen { get; } = 1; public int VirtualWidth => DefaultWidth; @@ -27,5 +29,9 @@ public int BufferHeight => DefaultHeight; public int BackgroundColor => DefaultBackgroundColor; + + public int VsyncNum => DefaultVsyncNum; + + public int VsyncDen => DefaultVsyncDen; } } diff --git a/BizHawk.Emulation.Common/CoreComms.cs b/BizHawk.Emulation.Common/CoreComms.cs index 3dafdf3c7d..04a124cd26 100644 --- a/BizHawk.Emulation.Common/CoreComms.cs +++ b/BizHawk.Emulation.Common/CoreComms.cs @@ -19,11 +19,6 @@ namespace BizHawk.Emulation.Common public ICoreFileProvider CoreFileProvider { get; set; } - public double VsyncRate => VsyncNum / (double)VsyncDen; - - public int VsyncNum { get; set; } = 60; - public int VsyncDen { get; set; } = 1; - // a core should set these if you wish to provide rom status information yourself. otherwise it will be calculated by the frontend in a way you may not like, using RomGame-related concepts. public string RomStatusAnnotation { get; set; } public string RomStatusDetails { get; set; } diff --git a/BizHawk.Emulation.Common/Extensions.cs b/BizHawk.Emulation.Common/Extensions.cs index a1bbd28375..91fc0deba8 100644 --- a/BizHawk.Emulation.Common/Extensions.cs +++ b/BizHawk.Emulation.Common/Extensions.cs @@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static ISoundProvider AsSoundProviderOrDefault(this IEmulator core) { return core.ServiceProvider.GetService() - ?? CachedNullSoundProviders.GetValue(core, e => new NullSound(e.CoreComm.VsyncNum, e.CoreComm.VsyncDen)); + ?? CachedNullSoundProviders.GetValue(core, e => new NullSound(core.VsyncNum(), core.VsyncDen())); } public static bool HasMemoryDomains(this IEmulator core) @@ -262,7 +262,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions { return false; } - + // once upon a time, we did a try { poke(peek) } here, but that was before Writable was added. the poke(peek) is not acceptable. If there are further problems, make sure Writable is correct. return true; } @@ -342,6 +342,31 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions return core.ServiceProvider.GetService(); } + public static int VsyncNum(this IEmulator core) + { + if (core != null && core.HasVideoProvider()) + { + //return core.AsVideoProvider().VsyncNum + } + + return 60; + } + + public static int VsyncDen(this IEmulator core) + { + if (core != null && core.HasVideoProvider()) + { + //return core.AsVideoProvider().VsyncDen + } + + return 1; + } + + public static int VsyncRate(this IEmulator core) + { + return core.VsyncNum() / core.VsyncDen(); + } + // TODO: a better place for these public static bool IsImplemented(this MethodInfo info) { @@ -366,4 +391,4 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions return !info.GetCustomAttributes(false).Any(a => a is FeatureNotImplemented); } } -} +} \ No newline at end of file diff --git a/BizHawk.Emulation.Common/Interfaces/Services/IVideoProvider.cs b/BizHawk.Emulation.Common/Interfaces/Services/IVideoProvider.cs index c619c3f600..fb343daa7d 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/IVideoProvider.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/IVideoProvider.cs @@ -44,6 +44,16 @@ /// int BufferHeight { get; } + /// + /// Gets the vsync Numerator. Combined with the can be used to calculate a precise vsync rate. + /// + int VsyncNum { get; } + + /// + /// Gets the vsync Denominator. Combined with the can be used to calculate a precise vsync rate. + /// + int VsyncDen { get; } + /// /// Gets the default color when no other color is applied /// Often cores will set this to something other than black diff --git a/BizHawk.Emulation.Cores/Calculator/TI83.IVideoProvider.cs b/BizHawk.Emulation.Cores/Calculator/TI83.IVideoProvider.cs index 1bcfde3352..e47b3a3247 100644 --- a/BizHawk.Emulation.Cores/Calculator/TI83.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Calculator/TI83.IVideoProvider.cs @@ -9,6 +9,8 @@ namespace BizHawk.Emulation.Cores.Calculators public int BufferWidth => 96; public int BufferHeight => 64; public int BackgroundColor => 0; + public int VsyncNum => NullVideo.DefaultVsyncNum; + public int VsyncDen => NullVideo.DefaultVsyncDen; public int[] GetVideoBuffer() { diff --git a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs index c75fcfe855..064f506a39 100644 --- a/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.IVideoProvider.cs @@ -18,5 +18,23 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII public int BufferWidth => 560; public int BufferHeight => 384; public int BackgroundColor => 0; + + public int VsyncNum + { + [FeatureNotImplemented] // TODO: precise numbers or confirm the default is okay + get + { + return NullVideo.DefaultVsyncNum; + } + } + + public int VsyncDen + { + [FeatureNotImplemented] // TODO: precise numbers or confirm the default is okay + get + { + return NullVideo.DefaultVsyncDen; + } + } } } diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs index d1ced3b781..40b2422460 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/C64.cs @@ -244,10 +244,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 _board = new Motherboard(this, initRegion, borderType, sidType, tapeDriveType, diskDriveType); InitRoms(diskDriveType); _board.Init(); - - // configure video - CoreComm.VsyncDen = _board.Vic.CyclesPerFrame; - CoreComm.VsyncNum = _board.Vic.CyclesPerSecond; } private void InitMedia() diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.VideoProvider.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.VideoProvider.cs index 81317a34be..d233789c20 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.VideoProvider.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.VideoProvider.cs @@ -70,5 +70,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS [SaveState.DoNotSave] public int VirtualHeight { get; private set; } + + [SaveState.DoNotSave] + public int VsyncNum => CyclesPerFrame; + + [SaveState.DoNotSave] + public int VsyncDen => CyclesPerSecond; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs index 397647a6e7..249468281a 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.Core.cs @@ -310,13 +310,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 } // dcfilter coefficent is from real observed hardware behavior: a latched "1" will fully decay by ~170 or so tia sound cycles - _tia = new TIA(this, _pal, Settings.SECAMColors, CoreComm.VsyncRate > 55.0 ? 735 : 882); - - int vsyncNum, vsyncDen; - _tia.GetFrameRate(out vsyncNum, out vsyncDen); - - CoreComm.VsyncNum = vsyncNum; - CoreComm.VsyncDen = vsyncDen; + _tia = new TIA(this, _pal, Settings.SECAMColors); _dcfilter = new DCFilter(_tia, 256); diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs index 0e13a61709..30baeb9d3f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Tia/TIA.cs @@ -14,6 +14,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 private const int BackColor = unchecked((int)0xff000000); + private int _vsyncNum, _vsyncDen; + static TIA() { // add alpha to palette entries @@ -234,7 +236,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 public int NominalNumScanlines => _pal ? 312 : 262; - public void GetFrameRate(out int num, out int den) + private void CalcFrameRate() { // TODO when sound timing is made exact: // NTSC refclock is actually 315 / 88 mhz @@ -243,8 +245,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 int clockrate = _pal ? 3546895 : 3579545; int clocksperframe = 228 * NominalNumScanlines; int gcd = (int)BigInteger.GreatestCommonDivisor(clockrate, clocksperframe); - num = clockrate / gcd; - den = clocksperframe / gcd; + _vsyncNum = clockrate / gcd; + _vsyncDen = clocksperframe / gcd; } private const int ScreenWidth = 160; @@ -325,14 +327,18 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 //public byte[] current_audio_register = new byte[6]; public short[] _local_audio_cycles = new short[2000]; - public TIA(Atari2600 core, bool pal, bool secam, int spf) + public TIA(Atari2600 core, bool pal, bool secam) { _core = core; _player0.ScanCnt = 8; _player1.ScanCnt = 8; _pal = pal; SetSECAM(secam); - _spf = spf; + + + CalcFrameRate(); + + _spf = _vsyncNum / (double)_vsyncDen > 55.0 ? 735 : 882; } public void SetSECAM(bool secam) @@ -387,6 +393,10 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 public int BackgroundColor => _core.Settings.BackgroundColor.ToArgb(); + public int VsyncNum => _vsyncNum; + + public int VsyncDen => _vsyncDen; + public int[] GetVideoBuffer() { return FrameBuffer; diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/7800/Atari7800.cs b/BizHawk.Emulation.Cores/Consoles/Atari/7800/Atari7800.cs index 549a0ec63d..be71bb7d64 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/7800/Atari7800.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/7800/Atari7800.cs @@ -205,10 +205,6 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800 _avProvider.ConnectToMachine(theMachine, GameInfo); - // to sync exactly with audio as this emulator creates and times it, the frame rate should be exactly 60:1 or 50:1 - CoreComm.VsyncNum = theMachine.FrameHZ; - CoreComm.VsyncDen = 1; - SetupMemoryDomains(hsc7800); } @@ -218,9 +214,13 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800 private class MyAVProvider : IVideoProvider, ISoundProvider, IDisposable { + // to sync exactly with audio as this emulator creates and times it, the frame rate should be exactly 60:1 or 50:1 + private int _frameHz; + public FrameBuffer Framebuffer { get; private set; } public void ConnectToMachine(MachineBase m, EMU7800.Win.GameProgram g) { + _frameHz = m.FrameHZ; Framebuffer = m.CreateFrameBuffer(); BufferWidth = Framebuffer.VisiblePitch; BufferHeight = Framebuffer.Scanlines; @@ -281,6 +281,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari7800 public int BufferWidth { get; private set; } public int BufferHeight { get; private set; } public int BackgroundColor => unchecked((int)0xff000000); + public int VsyncNum => _frameHz; + public int VsyncDen => 1; #region ISoundProvider diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.IVideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.IVideoProvider.cs index bafc2093aa..1af66a5d16 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.IVideoProvider.cs @@ -23,5 +23,9 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx public int BufferHeight { get; } public int BackgroundColor => unchecked((int)0xff000000); + + public int VsyncNum => 16000000; // 16.00 mhz refclock + + public int VsyncDen => 16 * 105 * 159; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.cs b/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.cs index b79a7cfd11..c9210f2ce2 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/lynx/Lynx.cs @@ -94,9 +94,6 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx Core = LibLynx.Create(realfile, realfile.Length, bios, bios.Length, pagesize0, pagesize1, false); try { - CoreComm.VsyncNum = 16000000; // 16.00 mhz refclock - CoreComm.VsyncDen = 16 * 105 * 159; - _savebuff = new byte[LibLynx.BinStateSize(Core)]; _savebuff2 = new byte[_savebuff.Length + 13]; diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/TMS9918A.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/TMS9918A.cs index 8e85420302..9bdf08c777 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/TMS9918A.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/TMS9918A.cs @@ -465,6 +465,24 @@ namespace BizHawk.Emulation.Cores.ColecoVision public int BufferHeight => 192; public int BackgroundColor => 0; + public int VsyncNum + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncNum; + } + } + + public int VsyncDen + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncDen; + } + } + private readonly int[] PaletteTMS9918 = { unchecked((int)0xFF000000), diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/STIC.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/STIC.cs index 83bdf84696..e6659057f5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/STIC.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/STIC.cs @@ -82,6 +82,24 @@ namespace BizHawk.Emulation.Cores.Intellivision public int BufferHeight => 208; public int BackgroundColor => 0; + public int VsyncNum + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncNum; + } + } + + public int VsyncDen + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncDen; + } + } + public void Reset() { Sr1 = true; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IVideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IVideoProvider.cs index e6d2d0668a..6abf919447 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IVideoProvider.cs @@ -17,6 +17,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA public int BackgroundColor => unchecked((int)0xff000000); + + public int VsyncNum => 262144; + + public int VsyncDen => 4389; + private readonly int[] _videobuff = new int[240 * 160]; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs index ae313818fb..5f3243a043 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs @@ -52,9 +52,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA ServiceProvider = ser; CoreComm = comm; - - CoreComm.VsyncNum = 262144; - CoreComm.VsyncDen = 4389; CoreComm.NominalWidth = 240; CoreComm.NominalHeight = 160; PutSettings(_settings); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.IVideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.IVideoProvider.cs index 71163d453c..704c382e61 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.IVideoProvider.cs @@ -19,6 +19,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA return _videobuff; } + public int VsyncNum => 262144; + + public int VsyncDen => 4389; + private readonly int[] _videobuff = new int[240 * 160]; private readonly int[] _videopalette = new int[65536]; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.cs index fd2498cd0e..119762e207 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/VBANext.cs @@ -71,8 +71,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA }; ser.Register(Tracer); - CoreComm.VsyncNum = 262144; - CoreComm.VsyncDen = 4389; CoreComm.NominalWidth = 240; CoreComm.NominalHeight = 160; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IVideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IVideoProvider.cs index d8aa4b0391..8ea0389617 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.IVideoProvider.cs @@ -21,5 +21,9 @@ public int BufferHeight => 144; public int BackgroundColor => 0; + + public int VsyncNum => 262144; + + public int VsyncDen => 4389; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs index 66f76e68d3..82ec12fbad 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -104,8 +104,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy InitMemoryCallbacks(); CoreComm = comm; - comm.VsyncNum = 262144; - comm.VsyncDen = 4389; comm.RomStatusAnnotation = null; comm.RomStatusDetails = null; comm.NominalWidth = 160; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs index 1a2848b02e..dcefcc8ef2 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.IVideoProvider.cs @@ -10,6 +10,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy public int BufferWidth { get { return 320; } } public int BufferHeight { get { return 144; } } + public int VsyncNum => L.VsyncNum; + + public int VsyncDen => L.VsyncDen; + public int BackgroundColor { get { return unchecked((int)0xff000000); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs index 4045604f5f..b0ec40a5e1 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GambatteLink.cs @@ -31,8 +31,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy L.ConnectMemoryCallbackSystem(_memorycallbacks); R.ConnectMemoryCallbackSystem(_memorycallbacks); - comm.VsyncNum = L.CoreComm.VsyncNum; - comm.VsyncDen = L.CoreComm.VsyncDen; comm.RomStatusAnnotation = null; comm.RomStatusDetails = "LEFT:\r\n" + L.CoreComm.RomStatusDetails + "RIGHT:\r\n" + R.CoreComm.RomStatusDetails; comm.NominalWidth = L.CoreComm.NominalWidth + R.CoreComm.NominalWidth; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs index 06e502c0c6..1efa8f8405 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs @@ -103,17 +103,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 _display_type = DisplayType.NTSC; break; } - switch (Region) - { - case DisplayType.NTSC: - comm.VsyncNum = 60000; - comm.VsyncDen = 1001; - break; - default: - comm.VsyncNum = 50; - comm.VsyncDen = 1; - break; - } StartThreadLoop(); @@ -134,6 +123,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 (ServiceProvider as BasicServiceProvider).Register(_videoProvider); (ServiceProvider as BasicServiceProvider).Register(_audioProvider.Resampler); + switch (Region) + { + case DisplayType.NTSC: + _videoProvider.VsyncNum = 60000; + _videoProvider.VsyncDen = 1001; + break; + default: + _videoProvider.VsyncNum = 50; + _videoProvider.VsyncDen = 1; + break; + } + string rsp; switch (_syncSettings.Rsp) { diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64VideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64VideoProvider.cs index 3d0ecc4499..b99baaf793 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64VideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64VideoProvider.cs @@ -43,6 +43,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 public int BufferWidth { get; private set; } public int BufferHeight { get; private set; } public int BackgroundColor { get { return 0; } } + public int VsyncNum { get; internal set; } + public int VsyncDen { get; internal set; } /// /// Fetches current frame buffer from mupen64 diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs index e338c72273..52ed59141a 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs @@ -211,8 +211,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES case Common.DisplayType.PAL: apu = new APU(this, apu, true); ppu.region = PPU.Region.PAL; - CoreComm.VsyncNum = 50; - CoreComm.VsyncDen = 1; + VsyncNum = 50; + VsyncDen = 1; cpuclockrate = 1662607; cpu_sequence = cpu_sequence_PAL; _display_type = DisplayType.PAL; @@ -220,8 +220,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES case Common.DisplayType.NTSC: apu = new APU(this, apu, false); ppu.region = PPU.Region.NTSC; - CoreComm.VsyncNum = 39375000; - CoreComm.VsyncDen = 655171; + VsyncNum = 39375000; + VsyncDen = 655171; cpuclockrate = 1789773; cpu_sequence = cpu_sequence_NTSC; break; @@ -229,8 +229,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES case Common.DisplayType.Dendy: apu = new APU(this, apu, false); ppu.region = PPU.Region.Dendy; - CoreComm.VsyncNum = 50; - CoreComm.VsyncDen = 1; + VsyncNum = 50; + VsyncDen = 1; cpuclockrate = 1773448; cpu_sequence = cpu_sequence_NTSC; _display_type = DisplayType.Dendy; @@ -246,7 +246,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES // apu has some specific power up bahaviour that we will emulate here apu.NESHardReset(); - if (SyncSettings.InitialWRamStatePattern != null && SyncSettings.InitialWRamStatePattern.Any()) { for (int i = 0; i < 0x800; i++) @@ -291,6 +290,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } + private int VsyncNum { get; set; } + private int VsyncDen { get; set; } + private IController _controller; bool resetSignal; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index 800ca1882a..8b9a7f8474 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -337,6 +337,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } } + public int VsyncNum => emu.VsyncNum; + public int VsyncDen => emu.VsyncDen; } MyVideoProvider videoProvider; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IVideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IVideoProvider.cs index 630ed11220..9d12143e57 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.IVideoProvider.cs @@ -8,6 +8,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES public int BufferHeight { get; private set; } public int BackgroundColor { get { return unchecked((int)0xff000000); } } + public int VsyncNum => 39375000; + public int VsyncDen => 655171; + public int[] GetVideoBuffer() { return VideoOutput; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs index 9559ddfee5..f0c7b21402 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/QuickNES/QuickNES.cs @@ -56,8 +56,6 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES string mappername = Marshal.PtrToStringAnsi(QN.qn_get_mapper(Context, ref mapper)); Console.WriteLine("QuickNES: Booted with Mapper #{0} \"{1}\"", mapper, mappername); BoardName = mappername; - CoreComm.VsyncNum = 39375000; - CoreComm.VsyncDen = 655171; PutSettings((QuickNESSettings)Settings ?? new QuickNESSettings()); _syncSettings = (QuickNESSyncSettings)SyncSettings ?? new QuickNESSyncSettings(); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IVideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IVideoProvider.cs index 453485a52a..0adaa19f1f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.IVideoProvider.cs @@ -19,6 +19,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES return _videoBuffer; } + public int VsyncNum { get; } + public int VsyncDen { get; } + private int[] _videoBuffer = new int[256 * 224]; private int _videoWidth = 256; private int _videoHeight = 224; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index 435059f28b..0c4ce275bf 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -156,14 +156,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES if (Api.Region == LibsnesApi.SNES_REGION.NTSC) { // similar to what aviout reports from snes9x and seems logical from bsnes first principles. bsnes uses that numerator (ntsc master clockrate) for sure. - CoreComm.VsyncNum = 21477272; - CoreComm.VsyncDen = 4 * 341 * 262; + VsyncNum = 21477272; + VsyncDen = 4 * 341 * 262; } else { // http://forums.nesdev.com/viewtopic.php?t=5367&start=19 - CoreComm.VsyncNum = 21281370; - CoreComm.VsyncDen = 4 * 341 * 312; + VsyncNum = 21281370; + VsyncDen = 4 * 341 * 312; } Api.CMD_power(); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs index 31ff2e9bb1..5cf5f88dbe 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES9X/Snes9x.cs @@ -66,6 +66,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X public int BufferHeight { get { return 224; } } public int BackgroundColor { get { return unchecked((int)0xff000000); } } + public int VsyncNum + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncNum; + } + } + + public int VsyncDen + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncDen; + } + } + #endregion #region ISoundProvider diff --git a/BizHawk.Emulation.Cores/Consoles/PC Engine/VDC.Render.cs b/BizHawk.Emulation.Cores/Consoles/PC Engine/VDC.Render.cs index 520f937fbd..37b6f4de9f 100644 --- a/BizHawk.Emulation.Cores/Consoles/PC Engine/VDC.Render.cs +++ b/BizHawk.Emulation.Cores/Consoles/PC Engine/VDC.Render.cs @@ -1,4 +1,5 @@ using System; +using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.PCEngine { @@ -439,5 +440,23 @@ namespace BizHawk.Emulation.Cores.PCEngine public int BufferWidth => FramePitch; public int BufferHeight => FrameHeight; public int BackgroundColor => vce.Palette[256]; + + public int VsyncNum + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncNum; + } + } + + public int VsyncDen + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncDen; + } + } } } diff --git a/BizHawk.Emulation.Cores/Consoles/PC Engine/VPC.cs b/BizHawk.Emulation.Cores/Consoles/PC Engine/VPC.cs index b6c5230ba4..6eaadf9ae9 100644 --- a/BizHawk.Emulation.Cores/Consoles/PC Engine/VPC.cs +++ b/BizHawk.Emulation.Cores/Consoles/PC Engine/VPC.cs @@ -528,5 +528,23 @@ namespace BizHawk.Emulation.Cores.PCEngine public int BufferWidth => FrameWidth; public int BufferHeight => FrameHeight; public int BackgroundColor => VCE.Palette[0]; + + public int VsyncNum + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncNum; + } + } + + public int VsyncDen + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncDen; + } + } } } diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs index bc66dad4fd..cc44499a99 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs @@ -94,9 +94,6 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem Region = DisplayType.NTSC; // all game gears run at 60hz/NTSC mode } - CoreComm.VsyncNum = Region == DisplayType.NTSC ? 60 : 50; - CoreComm.VsyncDen = 1; - RegionStr = SyncSettings.ConsoleRegion; if (RegionStr == "Auto") { diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/VDP.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/VDP.cs index 34234f1591..b5a3215fe9 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/VDP.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/VDP.cs @@ -496,5 +496,9 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem { get { return Palette[BackdropColor]; } } + + public int VsyncNum => DisplayType == DisplayType.NTSC ? 60 : 50; + + public int VsyncDen => 1; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs b/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs index f04cf1aa12..048bcd42be 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/Saturn/Yabause.cs @@ -346,6 +346,24 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn public int BufferHeight { get; private set; } public int BackgroundColor { get { return unchecked((int)0xff000000); } } + public int VsyncNum + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncNum; + } + } + + public int VsyncDen + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncDen; + } + } + #endregion #region ISyncSoundProvider diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IVideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IVideoProvider.cs index f22e2a3906..9c66e9aed0 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.IVideoProvider.cs @@ -17,6 +17,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx public int BackgroundColor { get { return unchecked((int)0xff000000); } } + public int VsyncNum { get; } + + public int VsyncDen { get; } + private int[] vidbuff = new int[0]; private int vwidth; private int vheight; diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs index 7ae2c963aa..4eb5c8042a 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx/GPGX.cs @@ -126,9 +126,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx int fpsnum = 60; int fpsden = 1; LibGPGX.gpgx_get_fps(ref fpsnum, ref fpsden); - CoreComm.VsyncNum = fpsnum; - CoreComm.VsyncDen = fpsden; - Region = CoreComm.VsyncRate > 55 ? DisplayType.NTSC : DisplayType.PAL; + VsyncNum = fpsnum; + VsyncDen = fpsden; + Region = VsyncNum / VsyncDen > 55 ? DisplayType.NTSC : DisplayType.PAL; } // compute state size diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IVideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IVideoProvider.cs index ee12610d1f..02fb6b3c64 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IVideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IVideoProvider.cs @@ -17,6 +17,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx64 public int BackgroundColor { get { return unchecked((int)0xff000000); } } + public int VsyncNum { get; } + + public int VsyncDen { get; } + private int[] vidbuff = new int[0]; private int vwidth; private int vheight; diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs index 79c349d0c0..176677a21e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.cs @@ -134,9 +134,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx64 int fpsnum = 60; int fpsden = 1; Core.gpgx_get_fps(ref fpsnum, ref fpsden); - CoreComm.VsyncNum = fpsnum; - CoreComm.VsyncDen = fpsden; - Region = CoreComm.VsyncRate > 55 ? DisplayType.NTSC : DisplayType.PAL; + VsyncNum = fpsnum; + VsyncDen = fpsden; + Region = VsyncNum / VsyncDen > 55 ? DisplayType.NTSC : DisplayType.PAL; } // compute state size diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSP/PSP.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSP/PSP.cs index 8cbbeb28cc..8e8dffc8a9 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sony/PSP/PSP.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSP/PSP.cs @@ -83,8 +83,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSP if (!good) throw new Exception("PPSSPP Init failed!"); - CoreComm.VsyncDen = 1; - CoreComm.VsyncNum = 60; CoreComm.RomStatusDetails = "It puts the scythe in the chicken or it gets the abyss again!"; attachedcore = this; @@ -173,6 +171,24 @@ namespace BizHawk.Emulation.Cores.Sony.PSP public int BufferHeight { get { return screenheight; } } public int BackgroundColor { get { return unchecked((int)0xff000000); } } + public int VsyncNum + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncNum; + } + } + + public int VsyncDen + { + [FeatureNotImplemented] + get + { + return NullVideo.DefaultVsyncDen; + } + } + readonly short[] audiobuffer = new short[2048 * 2]; int nsampavail = 0; public void GetSamplesSync(out short[] samples, out int nsamp) diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs index 3a56875142..56f570ff37 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Octoshock.cs @@ -331,14 +331,14 @@ namespace BizHawk.Emulation.Cores.Sony.PSX int VidClock_d = CpuClock_d * 7; if (SystemRegion == OctoshockDll.eRegion.EU) { - CoreComm.VsyncNum = VidClock_n; - CoreComm.VsyncDen = VidClock_d * 314 * 3406; + VsyncNum = VidClock_n; + VsyncDen = VidClock_d * 314 * 3406; SystemVidStandard = OctoshockDll.eVidStandard.PAL; } else { - CoreComm.VsyncNum = VidClock_n; - CoreComm.VsyncDen = VidClock_d * 263 * 3413; + VsyncNum = VidClock_n; + VsyncDen = VidClock_d * 263 * 3413; SystemVidStandard = OctoshockDll.eVidStandard.NTSC; } @@ -868,6 +868,9 @@ namespace BizHawk.Emulation.Cores.Sony.PSX public int BufferWidth { get; private set; } public int BufferHeight { get; private set; } public int BackgroundColor { get { return 0; } } + public int VsyncNum { get; private set; } + public int VsyncDen { get; private set; } + public System.Drawing.Size VideoProvider_Padding { get; private set; } #region Debugging diff --git a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs index 6f77792096..9f7b4e8423 100644 --- a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs +++ b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs @@ -38,9 +38,6 @@ namespace BizHawk.Emulation.Cores.WonderSwan if (!BizSwan.bizswan_load(Core, file, file.Length, ref ss, ref rotate)) throw new InvalidOperationException("bizswan_load() returned FALSE!"); - CoreComm.VsyncNum = 3072000; // master CPU clock, also pixel clock - CoreComm.VsyncDen = (144 + 15) * (224 + 32); // 144 vislines, 15 vblank lines; 224 vispixels, 32 hblank pixels - InitISaveRam(); InitVideo(rotate); @@ -216,6 +213,9 @@ namespace BizHawk.Emulation.Cores.WonderSwan public int BufferHeight { get; private set; } public int BackgroundColor { get { return unchecked((int)0xff000000); } } + public int VsyncNum => 3072000; // master CPU clock, also pixel clock + public int VsyncDen => (144 + 15) * (224 + 32); // 144 vislines, 15 vblank lines; 224 vispixels, 32 hblank pixels + #endregion } } diff --git a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs index 89258f348d..93351a0b46 100644 --- a/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs +++ b/BizHawk.Emulation.Cores/Libretro/LibretroCore.cs @@ -128,8 +128,8 @@ namespace BizHawk.Emulation.Cores.Libretro savebuff2 = new byte[savebuff.Length + 13]; // TODO: more precise - CoreComm.VsyncNum = (int)(10000000 * api.comm->env.retro_system_av_info.timing.fps); - CoreComm.VsyncDen = 10000000; + VsyncNum = (int)(10000000 * api.comm->env.retro_system_av_info.timing.fps); + VsyncDen = 10000000; SetupResampler(api.comm->env.retro_system_av_info.timing.fps, api.comm->env.retro_system_av_info.timing.sample_rate); (ServiceProvider as BasicServiceProvider).Register(resampler); @@ -217,6 +217,9 @@ namespace BizHawk.Emulation.Cores.Libretro int IVideoProvider.BufferWidth { get { return vidWidth; } } int IVideoProvider.BufferHeight { get { return vidHeight; } } + public int VsyncNum { get; private set; } + public int VsyncDen { get; private set; } + #region ISoundProvider SpeexResampler resampler; diff --git a/Settings.StyleCop b/Settings.StyleCop index c605d2a46e..bcf19d5058 100644 --- a/Settings.StyleCop +++ b/Settings.StyleCop @@ -14,6 +14,7 @@ savestate savestates Speex + vsync